From 2eb3ca741dbb6ec79af53d0def5c409da43a2dd2 Mon Sep 17 00:00:00 2001 From: Krantisinh Deshmukh Date: Fri, 1 Feb 2019 10:32:21 +0530 Subject: [PATCH 1/4] [Ramda] - Added type definition for R.move --- types/ramda/es/move.d.ts | 2 ++ types/ramda/index.d.ts | 8 ++++++++ types/ramda/ramda-tests.ts | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 types/ramda/es/move.d.ts diff --git a/types/ramda/es/move.d.ts b/types/ramda/es/move.d.ts new file mode 100644 index 0000000000..3df4ee626e --- /dev/null +++ b/types/ramda/es/move.d.ts @@ -0,0 +1,2 @@ +import { move } from '../index'; +export default move; diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index d84c148d96..a35b2612ee 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -26,6 +26,7 @@ // Drew Wyatt // John Ottenlips // Nitesh Phadatare +// Krantisinh Deshmukh // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -163,6 +164,7 @@ /// /// /// +/// /// /// /// @@ -1575,6 +1577,12 @@ declare namespace R { multiply(a: number, b: number): number; multiply(a: number): (b: number) => number; + /** + * Moves an item, at index `from`, to index `to`, in a list of elements. + * A new list will be created containing the new elements order. + */ + move: CurriedFunction3; + /** * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. * Any extraneous parameters will not be passed to the supplied function. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index c67ef3944d..abc7b60775 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -2762,3 +2762,20 @@ class Why { () => { R.bind(console.log, console); }; + +() => { + const sampleList = ['a', 'b', 'c', 'd', 'e', 'f']; + + R.move(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + R.move(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation + + const moveCurried1 = R.move(0, 2); + moveCurried1(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + + const moveCurried2 = R.move(0); + moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + + const moveCurried3 = R.move(0); + const moveCurried4 = moveCurried3(2); + moveCurried4(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] +}; From fe88e628b899dec72ef84ff5255aa4a607b65953 Mon Sep 17 00:00:00 2001 From: Krantisinh Deshmukh Date: Fri, 1 Feb 2019 12:36:10 +0530 Subject: [PATCH 2/4] [RAMDA] - Moved tests to list category. --- types/ramda/ramda-tests.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index abc7b60775..87c4c7a099 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1115,6 +1115,23 @@ interface Obj { R.addIndex(R.map)(squareEnds)([8, 5, 3, 0, 9]); // => [64, 5, 3, 0, 81] }; +() => { + const sampleList = ['a', 'b', 'c', 'd', 'e', 'f']; + + R.move(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + R.move(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation + + const moveCurried1 = R.move(0, 2); + moveCurried1(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + + const moveCurried2 = R.move(0); + moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + + const moveCurried3 = R.move(0); + const moveCurried4 = moveCurried3(2); + moveCurried4(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] +}; + () => { R.none(R.isNaN, [1, 2, 3]); // => true R.none(R.isNaN, [1, 2, 3, NaN]); // => false @@ -2762,20 +2779,3 @@ class Why { () => { R.bind(console.log, console); }; - -() => { - const sampleList = ['a', 'b', 'c', 'd', 'e', 'f']; - - R.move(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] - R.move(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation - - const moveCurried1 = R.move(0, 2); - moveCurried1(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] - - const moveCurried2 = R.move(0); - moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] - - const moveCurried3 = R.move(0); - const moveCurried4 = moveCurried3(2); - moveCurried4(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] -}; From fff62884caad593567558d422cf0f15728fa488b Mon Sep 17 00:00:00 2001 From: Krantisinh Deshmukh Date: Mon, 4 Feb 2019 12:57:43 +0530 Subject: [PATCH 3/4] [Ramda] - Improved type signatures of R.move. --- types/ramda/index.d.ts | 6 ++++-- types/ramda/ramda-tests.ts | 12 ++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index a35b2612ee..05b629137d 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1578,10 +1578,12 @@ declare namespace R { multiply(a: number): (b: number) => number; /** - * Moves an item, at index `from`, to index `to`, in a list of elements. + * Moves an item, at index `from`, to index `to`, in a `list` of elements. * A new list will be created containing the new elements order. */ - move: CurriedFunction3; + move(from: number, to: number, list: ReadonlyArray): T[]; + move(from: number, to: number): (list: ReadonlyArray) => T[]; + move(from: number): ((to: number, list: ReadonlyArray) => T[]); /** * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 87c4c7a099..6c568d4a56 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1118,18 +1118,14 @@ interface Obj { () => { const sampleList = ['a', 'b', 'c', 'd', 'e', 'f']; - R.move(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] - R.move(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation + R.move(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + R.move(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation const moveCurried1 = R.move(0, 2); - moveCurried1(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + moveCurried1(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] const moveCurried2 = R.move(0); - moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] - - const moveCurried3 = R.move(0); - const moveCurried4 = moveCurried3(2); - moveCurried4(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] }; () => { From 219f33284fb726b557ad52d190f05dbbffd94fff Mon Sep 17 00:00:00 2001 From: Krantisinh Deshmukh Date: Wed, 6 Feb 2019 10:08:43 +0530 Subject: [PATCH 4/4] [Ramda] - Added typings to support all combinations of curried versions of R.move --- types/ramda/index.d.ts | 5 ++++- types/ramda/ramda-tests.ts | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 05b629137d..459a351c33 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1583,7 +1583,10 @@ declare namespace R { */ move(from: number, to: number, list: ReadonlyArray): T[]; move(from: number, to: number): (list: ReadonlyArray) => T[]; - move(from: number): ((to: number, list: ReadonlyArray) => T[]); + move(from: number): { + (to: number, list: ReadonlyArray): T[]; + (to: number): (list: ReadonlyArray) => T[]; + }; /** * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 6c568d4a56..e4039483da 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1126,6 +1126,10 @@ interface Obj { const moveCurried2 = R.move(0); moveCurried2(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] + + const moveCurried3 = R.move(0); + const moveCurried4 = moveCurried3(2); + moveCurried4(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f'] }; () => {