diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 340b33e0266ccb..78018466b8220c 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -20,32 +20,6 @@ class F2 { } } -(() => { - R.type({}); // => "Object" - R.type(1); // => "Number" - R.type(false); // => "Boolean" - R.type("s"); // => "String" - R.type(null); // => "Null" - R.type([]); // => "Array" - R.type(/[A-z]/); // => "RegExp" -}); - -() => { - function takesOneArg(a: number) { - return [a]; - } - function takesTwoArgs(a: number, b: number) { - return [a, b]; - } - function takesThreeArgs(a: number, b: number, c: number) { - return [a, b, c]; - } - - const u1: (a: any) => any = R.unary(takesOneArg); - const u2: (a: any) => any = R.unary(takesTwoArgs); - const u3: (a: any) => any = R.unary(takesThreeArgs); -}; - /** R.__ */ () => { R.concat(R.__, [4, 5, 6])([1, 2, 3]); // [1, 2, 3, 4, 5, 6] @@ -85,12 +59,6 @@ class F2 { R.subtract(R.__)(5, 17); // 12 }; -() => { - const addFour = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d; - const uncurriedAddFour = R.uncurryN(4, addFour); - const res: number = uncurriedAddFour(1, 2, 3, 4); // => 10 -}; - () => { // coerceArray :: (a|[a]) -> [a] const coerceArray = R.unless(R.is(Array), R.of); @@ -98,11 +66,6 @@ class F2 { const b: number[] = coerceArray(1); // => [1] }; -() => { - const fn: (...args: string[]) => string = R.unapply(JSON.stringify); - const res: string = R.unapply(JSON.stringify)(1, 2, 3); // => '[1,2,3]' -}; - () => { const a: number = R.until(R.flip(R.gt)(100), R.multiply(2))(1); // => 128 }; @@ -127,28 +90,6 @@ function addAll() { // Basic example R.useWith(addAll, [double, square]); -function i(x: number) { - return x; -} -R.times(i, 5); - -(() => { - function isNotFour(x: number) { - return !(x === 4); - } - - R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3] -}); -(() => { - function f(n: number): false | [number, number] { - return n > 50 ? false : [-n, n + 10]; - } - - const a = R.unfold(f, 10); // => [-10, -20, -30, -40, -50] - const b = R.unfold(f); // => [-10, -20, -30, -40, -50] - const c = b(10); -}); - /********************* * List category */ @@ -157,107 +98,6 @@ R.times(i, 5); R.view(headLens, ["a", "b", "c"]); // => 'a' }; -() => { - const a: string[] = R.takeLast(1, ["foo", "bar", "baz"]); // => ['baz'] - const b: string[] = R.takeLast(2)(["foo", "bar", "baz"]); // => ['bar', 'baz'] - const c: string = R.takeLast(3, "ramda"); // => 'mda' - const d: string = R.takeLast(3)("ramda"); // => 'mda' -}; - -() => { - const isNotOne = (x: number) => x !== 1; - const a: number[] = R.takeLastWhile(isNotOne, [1, 2, 3, 4]); // => [2, 3, 4] - const b: number[] = R.takeLastWhile(isNotOne)([1, 2, 3, 4]); // => [2, 3, 4] -}; - -() => { - function isNotFour(x: number) { - return !(x === 4); - } - - R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3] - R.takeWhile(isNotFour)([1, 2, 3, 4]); // => [1, 2, 3] -}; - -() => { - const sayX = (x: number) => console.log("x is " + x); - const a: number = R.tap(sayX, 100); // => 100 -}; - -() => { - const a: boolean = R.test(/^x/, "xyz"); // => true - const b: boolean = R.test(/^y/)("xyz"); // => false -}; - -() => { - const x: unknown = R.thunkify(R.identity)(42)(); - const y: number = R.thunkify((a: number, b: number) => a + b)(25, 17)(); - const z: number = R.thunkify((a: number, b: number) => a + b)(25)(17)(); -}; - -() => { - const a1 = R.times(R.identity, 5); // => [0, 1, 2, 3, 4] - const a2 = R.times(R.identity)(5); // => [0, 1, 2, 3, 4] -}; - -() => { - class Point { - constructor(public x: number, public y: number) { - this.x = x; - this.y = y; - } - - toStringn() { - return `new Point(${this.x}, ${this.y})`; - } - } - R.toString(new Point(1, 2)); // => 'new Point(1, 2)' - - R.toString(42); // => '42' - R.toString("abc"); // => '"abc"' - R.toString([1, 2, 3]); // => '[1, 2, 3]' - R.toString({foo: 1, bar: 2, baz: 3}); // => '{"bar": 2, "baz": 3, "foo": 1}' - R.toString(new Date("2001-02-03T04:05:06Z")); // => 'new Date("2001-02-03T04:05:06.000Z")' -}; - -() => { - const numbers = [1, 2, 3, 4]; - const transducer = R.compose(R.map(R.add(1)), R.take(2)); - const fn = R.flip(R.append); - R.transduce(transducer, fn, [], numbers); // => [2, 3] - R.transduce(transducer, fn, [])(numbers); // => [2, 3] - R.transduce(transducer, fn)([], numbers); // => [2, 3] - R.transduce(transducer)(fn, [], numbers); // => [2, 3] -}; - -() => { - const a: Array> = R.transpose([[1, "a"], [2, "b"], [3, "c"]]); // => [[1, 2, 3], ['a', 'b', 'c']] - const b: Array> = R.transpose([[1, 2, 3], ["a", "b", "c"]]); // => [[1, 'a'], [2, 'b'], [3, 'c']] - const c: number[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]); // => [[10, 20, 30], [11, 31], [32]] -}; - -() => { - const of = Array.of; - const fn = (x: number) => Array.of(x + 1); - const list = [1, 2, 3]; - R.traverse(of, fn, list); - R.traverse(of, fn)(list); - R.traverse(of)(fn, list); -}; - -() => { - const a: boolean = R.tryCatch(R.prop("x"), R.F)({x: true}); // => true - const a1: boolean = R.tryCatch(R.prop<"x", true>("x"), R.F)({x: true}); // => true - const b: boolean = R.tryCatch(R.prop("x"), R.F)(null); // => false - const c: boolean = R.tryCatch(R.and, R.F)(true, true); // => true -}; - -() => { - R.uniq([1, 1, 2, 1]); // => [1, 2] - R.uniq([{}, {}]); // => [{}, {}] - R.uniq([1, "1"]); // => [1, '1'] -}; - () => { function strEq(a: any, b: any) { return String(a) === String(b); @@ -332,17 +172,6 @@ R.times(i, 5); R.view(xyLens, testObj); // => 2 }; -() => { - const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] - const b = R.toPairs({1: 'a'}); // => [['1', 'something']] -}; - -() => { - const f = new F(); - const a1 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] - const a2 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] -}; - () => { interface A { a: string; diff --git a/types/ramda/test/takeLast-tests.ts b/types/ramda/test/takeLast-tests.ts new file mode 100644 index 00000000000000..3939694b88c8c1 --- /dev/null +++ b/types/ramda/test/takeLast-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const a: string[] = R.takeLast(1, ['foo', 'bar', 'baz']); // => ['baz'] + const b: string[] = R.takeLast(2)(['foo', 'bar', 'baz']); // => ['bar', 'baz'] + const c: string = R.takeLast(3, 'ramda'); // => 'mda' + const d: string = R.takeLast(3)('ramda'); // => 'mda' +}; diff --git a/types/ramda/test/takeLastWhile-tests.ts b/types/ramda/test/takeLastWhile-tests.ts new file mode 100644 index 00000000000000..12673c01c3ea4f --- /dev/null +++ b/types/ramda/test/takeLastWhile-tests.ts @@ -0,0 +1,7 @@ +import * as R from 'ramda'; + +() => { + const isNotOne = (x: number) => x !== 1; + const a: number[] = R.takeLastWhile(isNotOne, [1, 2, 3, 4]); // => [2, 3, 4] + const b: number[] = R.takeLastWhile(isNotOne)([1, 2, 3, 4]); // => [2, 3, 4] +}; diff --git a/types/ramda/test/takeWhile-tests.ts b/types/ramda/test/takeWhile-tests.ts new file mode 100644 index 00000000000000..d1eea6b65cd33c --- /dev/null +++ b/types/ramda/test/takeWhile-tests.ts @@ -0,0 +1,10 @@ +import * as R from 'ramda'; + +() => { + function isNotFour(x: number) { + return !(x === 4); + } + + R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3] + R.takeWhile(isNotFour)([1, 2, 3, 4]); // => [1, 2, 3] +}; diff --git a/types/ramda/test/tap-tests.ts b/types/ramda/test/tap-tests.ts new file mode 100644 index 00000000000000..20a8e9e9bb7df6 --- /dev/null +++ b/types/ramda/test/tap-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const sayX = (x: number) => console.log('x is ' + x); + const a: number = R.tap(sayX, 100); // => 100 +}; diff --git a/types/ramda/test/test-tests.ts b/types/ramda/test/test-tests.ts new file mode 100644 index 00000000000000..d1b42fb00c400e --- /dev/null +++ b/types/ramda/test/test-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const a: boolean = R.test(/^x/, 'xyz'); // => true + const b: boolean = R.test(/^y/)('xyz'); // => false +}; diff --git a/types/ramda/test/thunkify-tests.ts b/types/ramda/test/thunkify-tests.ts new file mode 100644 index 00000000000000..b48d0184f6bd2f --- /dev/null +++ b/types/ramda/test/thunkify-tests.ts @@ -0,0 +1,7 @@ +import * as R from 'ramda'; + +() => { + const x: unknown = R.thunkify(R.identity)(42)(); + const y: number = R.thunkify((a: number, b: number) => a + b)(25, 17)(); + const z: number = R.thunkify((a: number, b: number) => a + b)(25)(17)(); +}; diff --git a/types/ramda/test/times-tests.ts b/types/ramda/test/times-tests.ts new file mode 100644 index 00000000000000..f61e768845c4cb --- /dev/null +++ b/types/ramda/test/times-tests.ts @@ -0,0 +1,11 @@ +import * as R from 'ramda'; + +function i(x: number) { + return x; +} +R.times(i, 5); + +() => { + const a1 = R.times(R.identity, 5); // => [0, 1, 2, 3, 4] + const a2 = R.times(R.identity)(5); // => [0, 1, 2, 3, 4] +}; diff --git a/types/ramda/test/toPairs-tests.ts b/types/ramda/test/toPairs-tests.ts new file mode 100644 index 00000000000000..528dfc86853960 --- /dev/null +++ b/types/ramda/test/toPairs-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const a = R.toPairs({ a: 1, b: 2, c: 3 }); // => [['a', 1], ['b', 2], ['c', 3]] + const b = R.toPairs({ 1: 'a' }); // => [['1', 'something']] +}; diff --git a/types/ramda/test/toPairsIn-tests.ts b/types/ramda/test/toPairsIn-tests.ts new file mode 100644 index 00000000000000..f0605c09bd17a8 --- /dev/null +++ b/types/ramda/test/toPairsIn-tests.ts @@ -0,0 +1,13 @@ +import * as R from 'ramda'; + +class F { + [k: string]: string; + x = 'X'; + y = 'Y'; +} + +() => { + const f = new F(); + const a1 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] + const a2 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] +}; diff --git a/types/ramda/test/toString-tests.ts b/types/ramda/test/toString-tests.ts new file mode 100644 index 00000000000000..45ee99034a8450 --- /dev/null +++ b/types/ramda/test/toString-tests.ts @@ -0,0 +1,21 @@ +import * as R from 'ramda'; + +() => { + class Point { + constructor(public x: number, public y: number) { + this.x = x; + this.y = y; + } + + toStringn() { + return `new Point(${this.x}, ${this.y})`; + } + } + R.toString(new Point(1, 2)); // => 'new Point(1, 2)' + + R.toString(42); // => '42' + R.toString('abc'); // => '"abc"' + R.toString([1, 2, 3]); // => '[1, 2, 3]' + R.toString({ foo: 1, bar: 2, baz: 3 }); // => '{"bar": 2, "baz": 3, "foo": 1}' + R.toString(new Date('2001-02-03T04:05:06Z')); // => 'new Date("2001-02-03T04:05:06.000Z")' +}; diff --git a/types/ramda/test/transduce-tests.ts b/types/ramda/test/transduce-tests.ts new file mode 100644 index 00000000000000..9650ed9702f5b7 --- /dev/null +++ b/types/ramda/test/transduce-tests.ts @@ -0,0 +1,14 @@ +import * as R from 'ramda'; + +() => { + const numbers = [1, 2, 3, 4]; + const transducer = R.compose( + R.map(R.add(1)), + R.take(2), + ); + const fn = R.flip(R.append); + R.transduce(transducer, fn, [], numbers); // => [2, 3] + R.transduce(transducer, fn, [])(numbers); // => [2, 3] + R.transduce(transducer, fn)([], numbers); // => [2, 3] + R.transduce(transducer)(fn, [], numbers); // => [2, 3] +}; diff --git a/types/ramda/test/transpose-tests.ts b/types/ramda/test/transpose-tests.ts new file mode 100644 index 00000000000000..1758957aa6b299 --- /dev/null +++ b/types/ramda/test/transpose-tests.ts @@ -0,0 +1,14 @@ +import * as R from 'ramda'; + +() => { + const a: Array> = R.transpose([ + [1, 'a'], + [2, 'b'], + [3, 'c'], + ]); // => [[1, 2, 3], ['a', 'b', 'c']] + const b: Array> = R.transpose([ + [1, 2, 3], + ['a', 'b', 'c'], + ]); // => [[1, 'a'], [2, 'b'], [3, 'c']] + const c: number[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]); // => [[10, 20, 30], [11, 31], [32]] +}; diff --git a/types/ramda/test/traverse-tests.ts b/types/ramda/test/traverse-tests.ts new file mode 100644 index 00000000000000..3f763473c69702 --- /dev/null +++ b/types/ramda/test/traverse-tests.ts @@ -0,0 +1,10 @@ +import * as R from 'ramda'; + +() => { + const of = Array.of; + const fn = (x: number) => Array.of(x + 1); + const list = [1, 2, 3]; + R.traverse(of, fn, list); + R.traverse(of, fn)(list); + R.traverse(of)(fn, list); +}; diff --git a/types/ramda/test/tryCatch-tests.ts b/types/ramda/test/tryCatch-tests.ts new file mode 100644 index 00000000000000..73e8b5f1d70dea --- /dev/null +++ b/types/ramda/test/tryCatch-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const a: boolean = R.tryCatch(R.prop('x'), R.F)({ x: true }); // => true + const a1: boolean = R.tryCatch(R.prop<'x', true>('x'), R.F)({ x: true }); // => true + const b: boolean = R.tryCatch(R.prop('x'), R.F)(null); // => false + const c: boolean = R.tryCatch(R.and, R.F)(true, true); // => true +}; diff --git a/types/ramda/test/type-tests.ts b/types/ramda/test/type-tests.ts new file mode 100644 index 00000000000000..43082d35830094 --- /dev/null +++ b/types/ramda/test/type-tests.ts @@ -0,0 +1,11 @@ +import * as R from 'ramda'; + +() => { + R.type({}); // => "Object" + R.type(1); // => "Number" + R.type(false); // => "Boolean" + R.type('s'); // => "String" + R.type(null); // => "Null" + R.type([]); // => "Array" + R.type(/[A-z]/); // => "RegExp" +}; diff --git a/types/ramda/test/unapply-tests.ts b/types/ramda/test/unapply-tests.ts new file mode 100644 index 00000000000000..9014f54f45120a --- /dev/null +++ b/types/ramda/test/unapply-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const fn: (...args: string[]) => string = R.unapply(JSON.stringify); + const res: string = R.unapply(JSON.stringify)(1, 2, 3); // => '[1,2,3]' +}; diff --git a/types/ramda/test/unary-tests.ts b/types/ramda/test/unary-tests.ts new file mode 100644 index 00000000000000..e5d68f2f8de14d --- /dev/null +++ b/types/ramda/test/unary-tests.ts @@ -0,0 +1,17 @@ +import * as R from 'ramda'; + +() => { + function takesOneArg(a: number) { + return [a]; + } + function takesTwoArgs(a: number, b: number) { + return [a, b]; + } + function takesThreeArgs(a: number, b: number, c: number) { + return [a, b, c]; + } + + const u1: (a: any) => any = R.unary(takesOneArg); + const u2: (a: any) => any = R.unary(takesTwoArgs); + const u3: (a: any) => any = R.unary(takesThreeArgs); +}; diff --git a/types/ramda/test/uncurryN-tests.ts b/types/ramda/test/uncurryN-tests.ts new file mode 100644 index 00000000000000..0d5efe554154bc --- /dev/null +++ b/types/ramda/test/uncurryN-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const addFour = (a: number) => (b: number) => (c: number) => (d: number) => + a + b + c + d; + const uncurriedAddFour = R.uncurryN(4, addFour); + const res: number = uncurriedAddFour(1, 2, 3, 4); // => 10 +}; diff --git a/types/ramda/test/unfold-tests.ts b/types/ramda/test/unfold-tests.ts new file mode 100644 index 00000000000000..3288d4f7a43217 --- /dev/null +++ b/types/ramda/test/unfold-tests.ts @@ -0,0 +1,11 @@ +import * as R from 'ramda'; + +() => { + function f(n: number): false | [number, number] { + return n > 50 ? false : [-n, n + 10]; + } + + const a = R.unfold(f, 10); // => [-10, -20, -30, -40, -50] + const b = R.unfold(f); // => [-10, -20, -30, -40, -50] + const c = b(10); +}; diff --git a/types/ramda/test/uniq-tests.ts b/types/ramda/test/uniq-tests.ts new file mode 100644 index 00000000000000..9a4f478bdf9384 --- /dev/null +++ b/types/ramda/test/uniq-tests.ts @@ -0,0 +1,7 @@ +import * as R from 'ramda'; + +() => { + R.uniq([1, 1, 2, 1]); // => [1, 2] + R.uniq([{}, {}]); // => [{}, {}] + R.uniq([1, '1']); // => [1, '1'] +}; diff --git a/types/ramda/tsconfig.json b/types/ramda/tsconfig.json index 520c7c9b435d8b..83072e7d32ebe5 100644 --- a/types/ramda/tsconfig.json +++ b/types/ramda/tsconfig.json @@ -211,6 +211,26 @@ "test/symmetricDifference-tests.ts", "test/symmetricDifferenceWith-tests.ts", "test/tail-tests.ts", - "test/take-tests.ts" + "test/take-tests.ts", + "test/takeLast-tests.ts", + "test/takeLastWhile-tests.ts", + "test/takeWhile-tests.ts", + "test/tap-tests.ts", + "test/test-tests.ts", + "test/thunkify-tests.ts", + "test/times-tests.ts", + "test/toPairs-tests.ts", + "test/toPairsIn-tests.ts", + "test/toString-tests.ts", + "test/transduce-tests.ts", + "test/transpose-tests.ts", + "test/traverse-tests.ts", + "test/tryCatch-tests.ts", + "test/type-tests.ts", + "test/unapply-tests.ts", + "test/unary-tests.ts", + "test/uncurryN-tests.ts", + "test/unfold-tests.ts", + "test/uniq-tests.ts" ] }