diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 9a236341c9..013d4983e1 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -111,11 +111,6 @@ class F2 { const b: number[] = coerceArray(1); // => [1] }; -(() => { - R.nthArg(1)("a", "b", "c"); // => 'b' - R.nthArg(-1)("a", "b", "c"); // => 'c' -}); - () => { const fn: (...args: string[]) => string = R.unapply(JSON.stringify); const res: string = R.unapply(JSON.stringify)(1, 2, 3); // => '[1,2,3]' @@ -268,34 +263,6 @@ R.times(i, 5); squareThenDoubleThenTriple(5); // => 150 })(); -(() => { - function multiply(a: number, b: number): number { - return a * b; - } - - const double = R.partial(multiply, [2]); - double(2); // => 4 - - function greet(salutation: string, title: string, firstName: string, lastName: string) { - return `${salutation}, ${title} ${firstName} ${lastName}!`; - } - - const sayHello = R.partial(greet, ["Hello"]); - const sayHelloToMs = R.partial(sayHello, ["Ms."]); - sayHelloToMs("Jane", "Jones"); // => 'Hello, Ms. Jane Jones!' - - const greetMsJaneJones = R.partialRight(greet, ["Ms.", "Jane", "Jones"]); - greetMsJaneJones("Hello"); // => 'Hello, Ms. Jane Jones!' -})(); - -(() => { - const addOneOnce = R.once((x: number) => x + 1); - addOneOnce(10); // => 11 - addOneOnce(addOneOnce(50)); // => 11 - - const str = R.once(() => 'test')(); -})(); - (() => { const numbers = [1, 2, 3]; R.reduce((a, b) => a + b, 10, numbers); // => 16; @@ -311,11 +278,6 @@ R.times(i, 5); R.reduceRight(flattenPairs, [], pairs); // => [ 'c', 3, 'b', 2, 'a', 1 ] })(); -(() => { - const b: number[][] = R.of([1]); // => [[1]] - const c: number[] = R.of(1); -}); - (() => { function isOdd(n: number) { return n % 2 === 1; @@ -376,16 +338,6 @@ R.times(i, 5); )([0, 1]); // => [1] }; -() => { - const testPath = ["x", 0, "y"]; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - - R.pathEq(testPath, 2, testObj); // => true - R.pathEq(testPath, 2)(testObj); // => true - R.pathEq(testPath)(2)(testObj); // => true - R.pathEq(testPath)(2, testObj); // => true -}; - () => { const xs: { [key: string]: string } = {a: "1", b: "0"}; R.propEq("a", "1", xs); // => true @@ -467,45 +419,6 @@ interface Obj { const headLens = R.lensIndex(0); R.view(headLens, ["a", "b", "c"]); // => 'a' R.set(headLens, "x", ["a", "b", "c"]); // => ['x', 'b', 'c'] - R.over(headLens, R.toUpper, ["a", "b", "c"]); // => ['A', 'b', 'c'] -}; - -() => { - 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(Number.isNaN, [1, 2, 3]); // => true - R.none(Number.isNaN, [1, 2, 3, NaN]); // => false - R.none(Number.isNaN, [1, 2, 3, NaN]); // => false -}; - -() => { - const list = ["foo", "bar", "baz", "quux"]; - R.nth(1, list); // => 'bar' - R.nth(-1, list); // => 'quux' - R.nth(-99, list); // => undefined - R.nth(-99)(list); // => undefined -}; - -() => { - R.partition(R.contains("s"), ["sss", "ttt", "foo", "bars"]); - R.partition(R.contains("s"))(["sss", "ttt", "foo", "bars"]); - R.partition((x: number) => x > 2, [1, 2, 3, 4]); - R.partition((x: number) => x > 2)([1, 2, 3, 4]); }; () => { @@ -886,23 +799,18 @@ type Pair = KeyValuePair; R.set(xLens, 4, {x: 1, y: 2}); // => {x: 4, y: 2} R.set(xLens)(4, {x: 1, y: 2}); // => {x: 4, y: 2} R.set(xLens, 4)({x: 1, y: 2}); // => {x: 4, y: 2} - R.over(xLens, R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} - R.over(xLens, R.negate)({x: 1, y: 2}); // => {x: -1, y: 2} - R.over(xLens)(R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} }; () => { const headLens = R.lensIndex(0); R.view(headLens, ["a", "b", "c"]); // => 'a' R.set(headLens, "x", ["a", "b", "c"]); // => ['x', 'b', 'c'] - R.over(headLens, R.toUpper, ["a", "b", "c"]); // => ['A', 'b', 'c'] }; () => { const xLens = R.lensProp("x"); R.view(xLens, {x: 1, y: 2}); // => 1 R.set(xLens, 4, {x: 1, y: 2}); // => {x: 4, y: 2} - R.over(xLens, R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} }; () => { @@ -911,110 +819,6 @@ type Pair = KeyValuePair; R.view(xyLens, testObj); // => 2 R.set(xyLens, 4, testObj); // => {x: [{y: 4, z: 3}, {y: 4, z: 5}]} - R.over(xyLens, R.negate, testObj); // => {x: [{y: -2, z: 3}, {y: 4, z: 5}]} -}; -() => { - const orValue = 11; - const orValueStr = "str"; - const testPath = ["x", 0, "y"]; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - const testObjMiss = {c: {b: 2}}; - - R.pathOr(orValue, testPath, testObj); // => 2 - R.pathOr(orValue, testPath)(testObj); // => 2 - R.pathOr(orValue)(testPath)(testObj); // => 2 - R.pathOr(orValue)(testPath, testObj); // => 2 - R.pathOr(orValue, testPath, testObjMiss); // => 11 - R.pathOr(orValueStr, testPath, testObjMiss); // => "str" -}; - -() => { - const a: boolean = R.pathSatisfies((x: number) => x > 0, ["x"], {x: 1, y: 2}); // => true - const b: boolean = R.pathSatisfies((x: number) => x > 0, ["x"])({x: 1, y: 2}); // => true - const c: boolean = R.pathSatisfies((x: number) => x > 0)(["x"])({x: 1, y: 2}); // => true -}; - -() => { - function isPositive(n: number) { - return n > 0; - } - - const a1 = R.pickBy(isPositive, {a: 1, b: 2, c: -1, d: 0, e: 5}); // => {a: 1, b: 2, e: 5} - function containsBackground(val: any) { - return val.bgcolor; - } - - const colors = {1: {color: "read"}, 2: {color: "black", bgcolor: "yellow"}}; - R.pickBy(containsBackground, colors); // => {2: {color: 'black', bgcolor: 'yellow'}} - - function isUpperCase(val: number, key: string) { - return key.toUpperCase() === key; - } - - R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); // => {A: 3, B: 4} -}; - -() => { - const a1 = R.pick(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} - const a2 = R.pick(["a", "e", "f"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1} - const a3 = R.pick(["a", "e", "f"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1} - const a4 = R.pick(["a", "e", "f"], [1, 2, 3, 4]); // => {a: 1} -}; - -() => { - const matchPhrases = (xs: string[]) => R.objOf("must", - R.map( - (x: string) => R.objOf("match_phrase", x), - xs - ) - ); - - const out: { must: Array<{ match_phrase: string }> } = - matchPhrases(["foo", "bar", "baz"]); -}; - -() => { - const classyGreeting = (name: { last: string; first: string }) => - `The name's ${name.last}, ${name.first} ${name.last}`; - const yellGreeting = R.o(R.toUpper, classyGreeting); - const str: string = yellGreeting({ first: 'James', last: 'Bond' }); - - const num: number = R.o(R.multiply(10), R.add(10))(-4); - const num2: number = R.o(R.multiply(10))(R.add(10))(-4); - const num3: number = R.o(R.multiply(10))(R.add(10), -4); - const num4: number = R.o(R.multiply(10), R.add(10), -4); -}; - -() => { - R.omit(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {b: 2, c: 3} - R.omit(["a", "d"])({a: 1, b: 2, c: 3, d: 4}); // => {b: 2, c: 3} -}; - -() => { - R.pair("foo", "bar"); // => ['foo', 'bar'] - const p = R.pair("foo", 1); // => ['foo', 'bar'] - const x: string = p[0]; - const y: number = p[1]; -}; - -() => { - const headLens = R.lensIndex(0); - R.over(headLens, R.toUpper, ["foo", "bar", "baz"]); // => ['FOO', 'bar', 'baz'] -}; - -() => { - R.pickAll(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} - R.pickAll(["a", "d"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} - R.pickAll(["a", "e", "f"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, e: undefined, f: undefined} - R.pickAll(["a", "e", "f"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1, e: undefined, f: undefined} -}; - -() => { - function isUpperCase(val: number, key: string) { - return key.toUpperCase() === key; - } - - R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); // => {A: 3, B: 4} }; () => { @@ -1139,17 +943,6 @@ type Pair = KeyValuePair; /***************************************************************** * Relation category */ -() => { - const testPath = ["x", 0, "y"]; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - - R.path(testPath, testObj); // => 2 - R.path(testPath)(testObj); // => 2 - - R.path(['a', 'b'])({c: {b: 2}}); // => undefined - R.path(['a', 'b'], {c: {b: 2}}); // => undefined -}; - () => { const sortByAgeDescending = R.sortBy(R.compose<{}, number, number>(R.negate, R.prop("age"))); const alice = { @@ -1272,38 +1065,3 @@ type Pair = KeyValuePair; R.replace(/([cfk])oo/g, (match, p1, offset) => `${p1}-${offset}`)("coo foo koo"); // => 'c0oo f4oo k8oo' R.replace(/([cfk])oo/g)((match, p1, offset) => `${p1}-${offset}`) ("coo foo koo"); // => 'c0oo f4oo k8oo' }; - -/***************************************************************** - * Logic category - */ - -() => { - R.not(true); // => false - R.not(false); // => true - R.not(0); // => true - R.not(1); // => false -}; - -class Why { - val: boolean; - - constructor(val: boolean) { - this.val = val; - } - - or(x: boolean) { - return this.val && x; - } -} -() => { - const x0: boolean = R.or(false, true); // => false - const x1: number | any[] = R.or(0, []); // => [] - const x2: number | any[] = R.or(0)([]); // => [] - const x3: string | null = R.or(null, ""); // => '' - - const why = new Why(true); - why.or(true); - const x4: Why | boolean = R.or(why, false); // false -}; - -// Curry tests diff --git a/types/ramda/test/not-tests.ts b/types/ramda/test/not-tests.ts new file mode 100644 index 0000000000..f654f46d80 --- /dev/null +++ b/types/ramda/test/not-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.not(true); // => false + R.not(false); // => true + R.not(0); // => true + R.not(1); // => false +}; diff --git a/types/ramda/test/nth-tests.ts b/types/ramda/test/nth-tests.ts new file mode 100644 index 0000000000..b823530c9a --- /dev/null +++ b/types/ramda/test/nth-tests.ts @@ -0,0 +1,9 @@ +import * as R from 'ramda'; + +() => { + const list = ['foo', 'bar', 'baz', 'quux']; + R.nth(1, list); // => 'bar' + R.nth(-1, list); // => 'quux' + R.nth(-99, list); // => undefined + R.nth(-99)(list); // => undefined +}; diff --git a/types/ramda/test/nthArg-tests.ts b/types/ramda/test/nthArg-tests.ts new file mode 100644 index 0000000000..2e512a6a99 --- /dev/null +++ b/types/ramda/test/nthArg-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + R.nthArg(1)('a', 'b', 'c'); // => 'b' + R.nthArg(-1)('a', 'b', 'c'); // => 'c' +}; diff --git a/types/ramda/test/o-tests.ts b/types/ramda/test/o-tests.ts new file mode 100644 index 0000000000..13508d6776 --- /dev/null +++ b/types/ramda/test/o-tests.ts @@ -0,0 +1,13 @@ +import * as R from 'ramda'; + +() => { + const classyGreeting = (name: { last: string; first: string }) => + `The name's ${name.last}, ${name.first} ${name.last}`; + const yellGreeting = R.o(R.toUpper, classyGreeting); + const str: string = yellGreeting({ first: 'James', last: 'Bond' }); + + const num: number = R.o(R.multiply(10), R.add(10))(-4); + const num2: number = R.o(R.multiply(10))(R.add(10))(-4); + const num3: number = R.o(R.multiply(10))(R.add(10), -4); + const num4: number = R.o(R.multiply(10), R.add(10), -4); +}; diff --git a/types/ramda/test/objOf-tests.ts b/types/ramda/test/objOf-tests.ts new file mode 100644 index 0000000000..7623dc7b76 --- /dev/null +++ b/types/ramda/test/objOf-tests.ts @@ -0,0 +1,12 @@ +import * as R from 'ramda'; + +() => { + const matchPhrases = (xs: string[]) => + R.objOf('must', R.map((x: string) => R.objOf('match_phrase', x), xs)); + + const out: { must: Array<{ match_phrase: string }> } = matchPhrases([ + 'foo', + 'bar', + 'baz', + ]); +}; diff --git a/types/ramda/test/of-tests.ts b/types/ramda/test/of-tests.ts new file mode 100644 index 0000000000..461d8f7de5 --- /dev/null +++ b/types/ramda/test/of-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + const b: number[][] = R.of([1]); // => [[1]] + const c: number[] = R.of(1); +}; diff --git a/types/ramda/test/omit-tests.ts b/types/ramda/test/omit-tests.ts new file mode 100644 index 0000000000..7979f6d037 --- /dev/null +++ b/types/ramda/test/omit-tests.ts @@ -0,0 +1,6 @@ +import * as R from 'ramda'; + +() => { + R.omit(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); // => {b: 2, c: 3} + R.omit(['a', 'd'])({ a: 1, b: 2, c: 3, d: 4 }); // => {b: 2, c: 3} +}; diff --git a/types/ramda/test/once-tests.ts b/types/ramda/test/once-tests.ts new file mode 100644 index 0000000000..6bbbf72009 --- /dev/null +++ b/types/ramda/test/once-tests.ts @@ -0,0 +1,9 @@ +import * as R from 'ramda'; + +(() => { + const addOneOnce = R.once((x: number) => x + 1); + addOneOnce(10); // => 11 + addOneOnce(addOneOnce(50)); // => 11 + + const str = R.once(() => 'test')(); +})(); diff --git a/types/ramda/test/or-tests.ts b/types/ramda/test/or-tests.ts new file mode 100644 index 0000000000..65600ab59d --- /dev/null +++ b/types/ramda/test/or-tests.ts @@ -0,0 +1,23 @@ +import * as R from 'ramda'; + +class Why { + val: boolean; + + constructor(val: boolean) { + this.val = val; + } + + or(x: boolean) { + return this.val && x; + } +} +() => { + const x0: boolean = R.or(false, true); // => false + const x1: number | any[] = R.or(0, []); // => [] + const x2: number | any[] = R.or(0)([]); // => [] + const x3: string | null = R.or(null, ''); // => '' + + const why = new Why(true); + why.or(true); + const x4: Why | boolean = R.or(why, false); // false +}; diff --git a/types/ramda/test/over-tests.ts b/types/ramda/test/over-tests.ts new file mode 100644 index 0000000000..70183b13a4 --- /dev/null +++ b/types/ramda/test/over-tests.ts @@ -0,0 +1,35 @@ +import * as R from 'ramda'; + +() => { + const headLens = R.lensIndex(0); + R.over(headLens, R.toUpper, ['a', 'b', 'c']); // => ['A', 'b', 'c'] +}; + +() => { + const xLens = R.lens(R.prop('x'), R.assoc('x')); + R.over(xLens, R.negate, { x: 1, y: 2 }); // => {x: -1, y: 2} + R.over(xLens, R.negate)({ x: 1, y: 2 }); // => {x: -1, y: 2} + R.over(xLens)(R.negate, { x: 1, y: 2 }); // => {x: -1, y: 2} +}; + +() => { + const headLens = R.lensIndex(0); + R.over(headLens, R.toUpper, ['a', 'b', 'c']); // => ['A', 'b', 'c'] +}; + +() => { + const xLens = R.lensProp('x'); + R.over(xLens, R.negate, { x: 1, y: 2 }); // => {x: -1, y: 2} +}; + +() => { + const xyLens = R.lensPath(['x', 0, 'y']); + const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] }; + + R.over(xyLens, R.negate, testObj); // => {x: [{y: -2, z: 3}, {y: 4, z: 5}]} +}; + +() => { + const headLens = R.lensIndex(0); + R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); // => ['FOO', 'bar', 'baz'] +}; diff --git a/types/ramda/test/pair-tests.ts b/types/ramda/test/pair-tests.ts new file mode 100644 index 0000000000..b2f9dd80d7 --- /dev/null +++ b/types/ramda/test/pair-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.pair('foo', 'bar'); // => ['foo', 'bar'] + const p = R.pair('foo', 1); // => ['foo', 'bar'] + const x: string = p[0]; + const y: number = p[1]; +}; diff --git a/types/ramda/test/partial-tests.ts b/types/ramda/test/partial-tests.ts new file mode 100644 index 0000000000..c2d8b8d2a9 --- /dev/null +++ b/types/ramda/test/partial-tests.ts @@ -0,0 +1,23 @@ +import * as R from 'ramda'; + +(() => { + function multiply(a: number, b: number): number { + return a * b; + } + + const double = R.partial(multiply, [2]); + double(2); // => 4 + + function greet( + salutation: string, + title: string, + firstName: string, + lastName: string, + ) { + return `${salutation}, ${title} ${firstName} ${lastName}!`; + } + + const sayHello = R.partial(greet, ['Hello']); + const sayHelloToMs = R.partial(sayHello, ['Ms.']); + sayHelloToMs('Jane', 'Jones'); // => 'Hello, Ms. Jane Jones!' +})(); diff --git a/types/ramda/test/partialRight-tests.ts b/types/ramda/test/partialRight-tests.ts new file mode 100644 index 0000000000..64f07ca825 --- /dev/null +++ b/types/ramda/test/partialRight-tests.ts @@ -0,0 +1,15 @@ +import * as R from 'ramda'; + +(() => { + function greet( + salutation: string, + title: string, + firstName: string, + lastName: string, + ) { + return `${salutation}, ${title} ${firstName} ${lastName}!`; + } + + const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']); + greetMsJaneJones('Hello'); // => 'Hello, Ms. Jane Jones!' +})(); diff --git a/types/ramda/test/partition-tests.ts b/types/ramda/test/partition-tests.ts new file mode 100644 index 0000000000..a279abc4f8 --- /dev/null +++ b/types/ramda/test/partition-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']); + R.partition(R.contains('s'))(['sss', 'ttt', 'foo', 'bars']); + R.partition((x: number) => x > 2, [1, 2, 3, 4]); + R.partition((x: number) => x > 2)([1, 2, 3, 4]); +}; diff --git a/types/ramda/test/path-tests.ts b/types/ramda/test/path-tests.ts new file mode 100644 index 0000000000..88cb579599 --- /dev/null +++ b/types/ramda/test/path-tests.ts @@ -0,0 +1,12 @@ +import * as R from 'ramda'; + +() => { + const testPath = ['x', 0, 'y']; + const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] }; + + R.path(testPath, testObj); // => 2 + R.path(testPath)(testObj); // => 2 + + R.path(['a', 'b'])({ c: { b: 2 } }); // => undefined + R.path(['a', 'b'], { c: { b: 2 } }); // => undefined +}; diff --git a/types/ramda/test/pathEq-tests.ts b/types/ramda/test/pathEq-tests.ts new file mode 100644 index 0000000000..e6a521c215 --- /dev/null +++ b/types/ramda/test/pathEq-tests.ts @@ -0,0 +1,11 @@ +import * as R from 'ramda'; + +() => { + const testPath = ['x', 0, 'y']; + const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] }; + + R.pathEq(testPath, 2, testObj); // => true + R.pathEq(testPath, 2)(testObj); // => true + R.pathEq(testPath)(2)(testObj); // => true + R.pathEq(testPath)(2, testObj); // => true +}; diff --git a/types/ramda/test/pathOr-tests.ts b/types/ramda/test/pathOr-tests.ts new file mode 100644 index 0000000000..3ee43f3ff3 --- /dev/null +++ b/types/ramda/test/pathOr-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + const orValue = 11; + const orValueStr = 'str'; + const testPath = ['x', 0, 'y']; + const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] }; + const testObjMiss = { c: { b: 2 } }; + + R.pathOr(orValue, testPath, testObj); // => 2 + R.pathOr(orValue, testPath)(testObj); // => 2 + R.pathOr(orValue)(testPath)(testObj); // => 2 + R.pathOr(orValue)(testPath, testObj); // => 2 + R.pathOr(orValue, testPath, testObjMiss); // => 11 + R.pathOr(orValueStr, testPath, testObjMiss); // => "str" +}; diff --git a/types/ramda/test/pathSatisfies-tests.ts b/types/ramda/test/pathSatisfies-tests.ts new file mode 100644 index 0000000000..3dac39041b --- /dev/null +++ b/types/ramda/test/pathSatisfies-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + const a: boolean = R.pathSatisfies((x: number) => x > 0, ['x'], { + x: 1, + y: 2, + }); // => true + const b: boolean = R.pathSatisfies((x: number) => x > 0, ['x'])({ + x: 1, + y: 2, + }); // => true + const c: boolean = R.pathSatisfies((x: number) => x > 0)(['x'])({ + x: 1, + y: 2, + }); // => true +}; diff --git a/types/ramda/test/pick-tests.ts b/types/ramda/test/pick-tests.ts new file mode 100644 index 0000000000..005f683603 --- /dev/null +++ b/types/ramda/test/pick-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + const a1 = R.pick(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); // => {a: 1, d: 4} + const a2 = R.pick(['a', 'e', 'f'], { a: 1, b: 2, c: 3, d: 4 }); // => {a: 1} + const a3 = R.pick(['a', 'e', 'f'])({ a: 1, b: 2, c: 3, d: 4 }); // => {a: 1} + const a4 = R.pick(['a', 'e', 'f'], [1, 2, 3, 4]); // => {a: 1} +}; diff --git a/types/ramda/test/pickAll-tests.ts b/types/ramda/test/pickAll-tests.ts new file mode 100644 index 0000000000..2a382e49c1 --- /dev/null +++ b/types/ramda/test/pickAll-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.pickAll(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }); // => {a: 1, d: 4} + R.pickAll(['a', 'd'])({ a: 1, b: 2, c: 3, d: 4 }); // => {a: 1, d: 4} + R.pickAll(['a', 'e', 'f'], { a: 1, b: 2, c: 3, d: 4 }); // => {a: 1, e: undefined, f: undefined} + R.pickAll(['a', 'e', 'f'])({ a: 1, b: 2, c: 3, d: 4 }); // => {a: 1, e: undefined, f: undefined} +}; diff --git a/types/ramda/test/pickBy-tests.ts b/types/ramda/test/pickBy-tests.ts new file mode 100644 index 0000000000..fd1c3ced77 --- /dev/null +++ b/types/ramda/test/pickBy-tests.ts @@ -0,0 +1,32 @@ +import * as R from 'ramda'; + +() => { + function isPositive(n: number) { + return n > 0; + } + + const a1 = R.pickBy(isPositive, { a: 1, b: 2, c: -1, d: 0, e: 5 }); // => {a: 1, b: 2, e: 5} + function containsBackground(val: any) { + return val.bgcolor; + } + + const colors = { + 1: { color: 'read' }, + 2: { color: 'black', bgcolor: 'yellow' }, + }; + R.pickBy(containsBackground, colors); // => {2: {color: 'black', bgcolor: 'yellow'}} + + function isUpperCase(val: number, key: string) { + return key.toUpperCase() === key; + } + + R.pickBy(isUpperCase, { a: 1, b: 2, A: 3, B: 4 }); // => {A: 3, B: 4} +}; + +() => { + function isUpperCase(val: number, key: string) { + return key.toUpperCase() === key; + } + + R.pickBy(isUpperCase, { a: 1, b: 2, A: 3, B: 4 }); // => {A: 3, B: 4} +}; diff --git a/types/ramda/tsconfig.json b/types/ramda/tsconfig.json index ac0aa874fb..1e24cd964f 100644 --- a/types/ramda/tsconfig.json +++ b/types/ramda/tsconfig.json @@ -150,6 +150,27 @@ "test/multiply-tests.ts", "test/nAry-tests.ts", "test/negate-tests.ts", - "test/none-tests.ts" + "test/none-tests.ts", + "test/not-tests.ts", + "test/nth-tests.ts", + "test/nthArg-tests.ts", + "test/o-tests.ts", + "test/objOf-tests.ts", + "test/of-tests.ts", + "test/omit-tests.ts", + "test/once-tests.ts", + "test/or-tests.ts", + "test/over-tests.ts", + "test/pair-tests.ts", + "test/partial-tests.ts", + "test/partialRight-tests.ts", + "test/partition-tests.ts", + "test/path-tests.ts", + "test/pathEq-tests.ts", + "test/pathOr-tests.ts", + "test/pathSatisfies-tests.ts", + "test/pick-tests.ts", + "test/pickAll-tests.ts", + "test/pickBy-tests.ts" ] } \ No newline at end of file