diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 46ef6c7d54..0b3cf54b46 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -99,9 +99,6 @@ class F2 { const u2: (a: any) => any = R.unary(takesTwoArgs); const u3: (a: any) => any = R.unary(takesThreeArgs); - R.binary(takesTwoArgs); - R.binary(takesThreeArgs); - function addTwoNumbers(a: number, b: number) { return a + b; } @@ -212,143 +209,6 @@ class F2 { const b: string = truncate("0123456789ABC"); // => '0123456789…' }; -/* compose */ -() => { - function double(x: number): number { - return x + x; - } - - function limit10(x: number): boolean { - return x >= 10; - } - - const func: (x: number) => boolean = R.compose(limit10, double); - const res: boolean = R.compose(limit10, double)(10); - - const f0 = (s: string) => +s; // string -> number - const f1 = (n: number) => n === 1; // number -> boolean - const f2: (s: string) => boolean = R.compose(f1, f0); // string -> boolean - - // akward example that bounces types between number and string - const g0 = (list: number[]) => R.map(R.inc, list); - const g1 = R.dropWhile(R.gt(10)); - const g2 = R.map((i: number) => i > 5 ? "bigger" : "smaller"); - const g3 = R.all((i: string) => i === "smaller"); - const g = R.compose(g3, g2, g1, g0); - const g_res: boolean = g([1, 2, 10, 13]); - - // compose with last function taking no params - const f10 = () => 'str'; - const f11 = (str: string) => str; - const f12: () => string = R.compose(f11, f10); -}; - -/* composeK */ -() => { - const get = (prop: string) => (obj: any): any[] => { - const propVal = obj[prop]; - if (propVal) { - return [propVal]; - } else { - return []; - } - }; - - const getStateCode: (input: any) => any[] = R.composeK( - R.compose((val) => [val], R.toUpper), - get('state'), - get('address'), - get('user'), - ); - getStateCode({ user: { address: { state: "ny" } } }); // => [] - getStateCode({}); // => [] - - const nextThree = (num: number): number[] => ([num, num + 1, num + 2]); - const onlyOverNine = (num: number): number[] => num > 9 ? [num] : []; - const toString = (input: any): string[] => [`${input}`]; - const split = (input: string): string[] => input.split(''); - - const composed: (num: number) => string[] = R.composeK( - split, - toString, - onlyOverNine, - nextThree, - ); -}; - -() => { - const get = (prop: string) => (obj: any): any[] => { - const propVal = obj[prop]; - if (propVal) { - return [propVal]; - } else { - return []; - } - }; - - const getStateCode: (input: any) => any[] = R.composeWith( - R.chain, - [ - R.compose((val) => [val], R.toUpper), - get('state'), - get('address'), - get('user'), - ], - ); - getStateCode({ user: { address: { state: "ny" } } }); // => [] - getStateCode({}); // => [] - - const nextThree = (num: number): number[] => ([num, num + 1, num + 2]); - const onlyOverNine = (num: number): number[] => num > 9 ? [num] : []; - const toString = (input: any): string[] => [`${input}`]; - const split = (input: string): string[] => input.split(''); - - const composed: (num: number) => string[] = R.composeWith( - R.chain, - [ - split, - toString, - onlyOverNine, - nextThree, - ], - ); - const composed2: (num: number) => string[] = R.composeWith(R.chain)([ - split, - toString, - onlyOverNine, - nextThree, - ]); -}; - -/* composeP */ -() => { - interface User { - name: string; - followers: string[]; - } - interface Db { - users: { [index: string]: User }; - } - const db: Db = { - users: { - JOE: { - name: 'Joe', - followers: ['STEVE', 'SUZY'] - } - } - }; - - // We'll pretend to do a db lookup which returns a promise - const lookupUser = (userId: string): Promise => Promise.resolve(db.users[userId]); - const lookupFollowers = (user: User): Promise => Promise.resolve(user.followers); - lookupUser('JOE').then(lookupFollowers); - - // followersForUser :: String -> Promise [UserId] - const followersForUser: (input: string) => Promise = R.composeP(lookupFollowers, lookupUser); - followersForUser('JOE').then(followers => console.log('Followers:', followers)); - // Followers: ["STEVE","SUZY"] -}; - /* pipe */ () => { const func: (x: number) => string = R.pipe(double, double, shout); @@ -484,8 +344,6 @@ R.useWith(addAll, [double, square]); } R.forEach(printXPlusFive, [1, 2, 3]); - R.clone([{}, {}, {}]); - R.clone([1, 2, 3]); })(); // (() => { @@ -679,43 +537,6 @@ R.times(i, 5); /********************* * List category */ -() => { - function duplicate(n: number) { - return [n, n]; - } - - R.chain(duplicate, [1, 2, 3]); // => [1, 1, 2, 2, 3, 3] - R.chain(duplicate)([1, 2, 3]); // => [1, 1, 2, 2, 3, 3] - const result1: number[] = R.chain(R.append, R.head)([ - 1, - 2, - 3 - ]); // => [1, 2, 3, 1] -}; - -() => { - R.clamp(1, 10, -1); // => 1 - R.clamp(1, 10)(11); // => 10 - R.clamp(1)(10, 4); // => 4 - R.clamp("a", "d", "e"); // => 'd' -}; - -() => { - R.concat([], []); // => [] - R.concat([4, 5, 6], [1, 2, 3]); // => [4, 5, 6, 1, 2, 3] - R.concat([4, 5, 6])([1, 2, 3]); // => [4, 5, 6, 1, 2, 3] - R.concat("ABC")("DEF"); // 'ABCDEF' -}; - -() => { - R.contains(3)([1, 2, 3]); // => true - R.contains(3, [1, 2, 3]); // => true - R.contains(4)([1, 2, 3]); // => false - R.contains({})([{}, {}]); // => false - const obj = {}; - R.contains(obj)([{}, obj, {}]); // => true -}; - () => { R.drop(3, [1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] R.drop(3)([1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] @@ -1313,24 +1134,6 @@ type Pair = KeyValuePair; R.sort(diff)([4, 2, 7, 5]); // => [2, 4, 5, 7] }; -() => { - const f = R.cond([ - [x => x === 0, () => "a"], - [() => true, () => "b"], - ]); - f(0); // $ExpectType string - f(""); // $ExpectError - f(1, 2); // $ExpectType string - - const g = R.cond([ - [(a, b) => a === b, () => "a"], - [() => true, () => "b"], - ]); - g(0); - g(""); - g(1, ""); -}; - () => { R.tail(["fi", "fo", "fum"]); // => ['fo', 'fum'] R.tail([1, 2, 3]); // => [2, 3] @@ -1553,17 +1356,6 @@ type Pair = KeyValuePair; R.dissocPath(testPath)(testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} }; -() => { - const obj1 = [{}, {}, {}]; - const obj2 = [{a: 1}, {a: 2}, {a: 3}]; - const a1: any[] = R.clone(obj1); - const a2: Array<{ a: number }> = R.clone(obj2); - const a3: any = R.clone({}); - const a4: number = R.clone(10); - const a5: string = R.clone("foo"); - const a6: number = R.clone(Date.now()); -}; - () => { const o1 = {a: 1, b: 2, c: 3, d: 4}; const o2 = {a: 10, b: 20, c: 3, d: 40}; @@ -2014,9 +1806,6 @@ class Rectangle { () => { R.props(["x", "y"], {x: 1, y: 2}); // => [1, 2] - - const fullName = R.compose(R.join(" "), R.props(["first", "last"])); - fullName({last: "Bullet-Tooth", age: 33, first: "Tony"}); // => 'Tony Bullet-Tooth' }; () => { @@ -2087,45 +1876,6 @@ class Rectangle { const a: number[] = R.without([1, 2], [1, 2, 1, 3, 4]); // => [3, 4] }; -() => { - function takesThreeArgs(a: number, b: number, c: number) { - return [a, b, c]; - } - - takesThreeArgs.length; // => 3 - takesThreeArgs(1, 2, 3); // => [1, 2, 3] - - const takesTwoArgs = R.binary(takesThreeArgs); - takesTwoArgs.length; // => 2 - // Only 2 arguments are passed to the wrapped function - takesTwoArgs(1, 2, 3); // => [1, 2, undefined] -}; - -() => { - const indentN = R.pipe(R.times(R.always(" ")), - R.join(""), - R.replace(/^(?!$)/gm) - ); - - const format = R.converge( - R.call, [ - R.pipe(R.prop<"indent", number>("indent"), indentN), - R.prop("value") - ] - ); - - format({indent: 2, value: "foo\nbar\nbaz\n"}); // => ' foo\n bar\n baz\n' -}; - -() => { - interface T { age: number; } - const cmp = R.comparator((a: T, b: T) => a.age < b.age); - const people = [ - {name: "Agy", age: 33}, {name: "Bib", age: 15}, {name: "Cari", age: 16} - ]; - R.sort(cmp, people); -}; - () => { const people = [ {name: 'Agy', age: 33}, {name: 'Bib', age: 15}, {name: 'Cari', age: 16} @@ -2134,68 +1884,6 @@ class Rectangle { R.sortWith([R.ascend(R.prop('age')), R.descend(R.prop('name'))], people); }; -() => { - function add(a: number, b: number) { - return a + b; - } - - function multiply(a: number, b: number) { - return a * b; - } - - function subtract(a: number, b: number) { - return a - b; - } - - // ≅ multiply( add(1, 2), subtract(1, 2) ); - const x: number = R.converge(multiply, [add, subtract])(1, 2); // => -3 - - function add3(a: number, b: number, c: number) { - return a + b + c; - } - - const y: number = R.converge(add3, [multiply, add, subtract])(1, 2); // => 4 -}; - -() => { - const f0 = R.compose(Math.pow); - const f1 = R.compose(R.negate, Math.pow); - const f2 = R.compose(R.inc, R.negate, Math.pow); - const f3 = R.compose(R.inc, R.inc, R.negate, Math.pow); - const f4 = R.compose(R.inc, R.inc, R.inc, R.negate, Math.pow); - const f5 = R.compose(R.inc, R.inc, R.inc, R.inc, R.negate, Math.pow); - const x0: number = f0(3, 4); // -(3^4) + 1 - const x1: number = f1(3, 4); // -(3^4) + 1 - const x2: number = f2(3, 4); // -(3^4) + 1 - const x3: number = f3(3, 4); // -(3^4) + 1 - const x4: number = f4(3, 4); // -(3^4) + 1 - const x5: number = f5(3, 4); // -(3^4) + 1 -}; - -() => { - function fn(a: string, b: number, c: string) { - return [a, b, c]; - } - - const gn = R.compose(R.length, fn); - const x: number = gn("Hello", 4, "world"); -}; - -(() => { - function Circle(r: number, colors: string) { - this.r = r; - this.colors = colors; - } - - Circle.prototype.area = function() { return Math.PI * Math.pow(this.r, 2); }; - - const circleN = R.constructN(1, Circle); - circleN(10, "red"); - circleN(10); - const circle = R.construct(Circle); - circle(10, "red"); -})(); - /***************************************************************** * Relation category */ @@ -2603,31 +2291,6 @@ class Rectangle { * Logic category */ -() => { - function gt10(x: number) { - return x > 10; - } - - function even(x: number) { - return x % 2 === 0; - } - - const f = R.both(gt10, even); - const g = R.both(gt10)(even); - f(100); // => true - f(101); // => false -}; - -() => { - function isEven(n: number) { - return n % 2 === 0; - } - - const isOdd = R.complement(isEven); - isOdd(21); // => true - isOdd(42); // => false -}; - (() => { R.eqBy(Math.abs, 5, -5); // => true }); @@ -2737,8 +2400,4 @@ class Why { R.intersection([1, 2, 3])([2, 3, 3, 4]); // => [2, 3] }; -() => { - R.bind(console.log, console); -}; - // Curry tests diff --git a/types/ramda/test/binary-tests.ts b/types/ramda/test/binary-tests.ts new file mode 100644 index 0000000000..a8cb444b6e --- /dev/null +++ b/types/ramda/test/binary-tests.ts @@ -0,0 +1,27 @@ +import * as R from 'ramda'; + +() => { + function takesThreeArgs(a: number, b: number, c: number) { + return [a, b, c]; + } + + takesThreeArgs.length; // => 3 + takesThreeArgs(1, 2, 3); // => [1, 2, 3] + + const takesTwoArgs = R.binary(takesThreeArgs); + takesTwoArgs.length; // => 2 + // Only 2 arguments are passed to the wrapped function + takesTwoArgs(1, 2, 3); // => [1, 2, undefined] +}; + +() => { + function takesTwoArgs(a: number, b: number) { + return [a, b]; + } + function takesThreeArgs(a: number, b: number, c: number) { + return [a, b, c]; + } + + R.binary(takesTwoArgs); + R.binary(takesThreeArgs); +}; diff --git a/types/ramda/test/bind-tests.ts b/types/ramda/test/bind-tests.ts new file mode 100644 index 0000000000..5d90f70b65 --- /dev/null +++ b/types/ramda/test/bind-tests.ts @@ -0,0 +1,5 @@ +import * as R from 'ramda'; + +() => { + R.bind(console.log, console); +}; diff --git a/types/ramda/test/both-tests.ts b/types/ramda/test/both-tests.ts new file mode 100644 index 0000000000..d261369554 --- /dev/null +++ b/types/ramda/test/both-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + const f = R.both(gt10, even); + const g = R.both(gt10)(even); + f(100); // => true + f(101); // => false +}; diff --git a/types/ramda/test/chain-tests.ts b/types/ramda/test/chain-tests.ts new file mode 100644 index 0000000000..4f7635fd13 --- /dev/null +++ b/types/ramda/test/chain-tests.ts @@ -0,0 +1,14 @@ +import * as R from 'ramda'; + +() => { + function duplicate(n: number) { + return [n, n]; + } + + R.chain(duplicate, [1, 2, 3]); // => [1, 1, 2, 2, 3, 3] + R.chain(duplicate)([1, 2, 3]); // => [1, 1, 2, 2, 3, 3] + const result1: number[] = R.chain( + R.append, + R.head, + )([1, 2, 3]); // => [1, 2, 3, 1] +}; diff --git a/types/ramda/test/clamp-tests.ts b/types/ramda/test/clamp-tests.ts new file mode 100644 index 0000000000..7488ace53c --- /dev/null +++ b/types/ramda/test/clamp-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.clamp(1, 10, -1); // => 1 + R.clamp(1, 10)(11); // => 10 + R.clamp(1)(10, 4); // => 4 + R.clamp('a', 'd', 'e'); // => 'd' +}; diff --git a/types/ramda/test/clone-tests.ts b/types/ramda/test/clone-tests.ts new file mode 100644 index 0000000000..75c3ed89b7 --- /dev/null +++ b/types/ramda/test/clone-tests.ts @@ -0,0 +1,17 @@ +import * as R from 'ramda'; + +() => { + const obj1 = [{}, {}, {}]; + const obj2 = [{ a: 1 }, { a: 2 }, { a: 3 }]; + const a1: any[] = R.clone(obj1); + const a2: Array<{ a: number }> = R.clone(obj2); + const a3: any = R.clone({}); + const a4: number = R.clone(10); + const a5: string = R.clone('foo'); + const a6: number = R.clone(Date.now()); +}; + +(() => { + R.clone([{}, {}, {}]); + R.clone([1, 2, 3]); +})(); diff --git a/types/ramda/test/comparator-tests.ts b/types/ramda/test/comparator-tests.ts new file mode 100644 index 0000000000..ada8ed5c17 --- /dev/null +++ b/types/ramda/test/comparator-tests.ts @@ -0,0 +1,14 @@ +import * as R from 'ramda'; + +() => { + interface T { + age: number; + } + const cmp = R.comparator((a: T, b: T) => a.age < b.age); + const people = [ + { name: 'Agy', age: 33 }, + { name: 'Bib', age: 15 }, + { name: 'Cari', age: 16 }, + ]; + R.sort(cmp, people); +}; diff --git a/types/ramda/test/complement-tests.ts b/types/ramda/test/complement-tests.ts new file mode 100644 index 0000000000..43b97aa90f --- /dev/null +++ b/types/ramda/test/complement-tests.ts @@ -0,0 +1,11 @@ +import * as R from 'ramda'; + +() => { + function isEven(n: number) { + return n % 2 === 0; + } + + const isOdd = R.complement(isEven); + isOdd(21); // => true + isOdd(42); // => false +}; diff --git a/types/ramda/test/compose-tests.ts b/types/ramda/test/compose-tests.ts new file mode 100644 index 0000000000..11c0fd7296 --- /dev/null +++ b/types/ramda/test/compose-tests.ts @@ -0,0 +1,108 @@ +import * as R from 'ramda'; + +() => { + function double(x: number): number { + return x + x; + } + + function limit10(x: number): boolean { + return x >= 10; + } + + const func: (x: number) => boolean = R.compose( + limit10, + double, + ); + const res: boolean = R.compose( + limit10, + double, + )(10); + + const f0 = (s: string) => +s; // string -> number + const f1 = (n: number) => n === 1; // number -> boolean + const f2: (s: string) => boolean = R.compose( + f1, + f0, + ); // string -> boolean + + // akward example that bounces types between number and string + const g0 = (list: number[]) => R.map(R.inc, list); + const g1 = R.dropWhile(R.gt(10)); + const g2 = R.map((i: number) => (i > 5 ? 'bigger' : 'smaller')); + const g3 = R.all((i: string) => i === 'smaller'); + const g = R.compose( + g3, + g2, + g1, + g0, + ); + const g_res: boolean = g([1, 2, 10, 13]); + + // compose with last function taking no params + const f10 = () => 'str'; + const f11 = (str: string) => str; + const f12: () => string = R.compose( + f11, + f10, + ); +}; + +() => { + const fullName = R.compose( + R.join(' '), + R.props(['first', 'last']), + ); + fullName({ last: 'Bullet-Tooth', age: 33, first: 'Tony' }); // => 'Tony Bullet-Tooth' +}; + +() => { + const f0 = R.compose(Math.pow); + const f1 = R.compose( + R.negate, + Math.pow, + ); + const f2 = R.compose( + R.inc, + R.negate, + Math.pow, + ); + const f3 = R.compose( + R.inc, + R.inc, + R.negate, + Math.pow, + ); + const f4 = R.compose( + R.inc, + R.inc, + R.inc, + R.negate, + Math.pow, + ); + const f5 = R.compose( + R.inc, + R.inc, + R.inc, + R.inc, + R.negate, + Math.pow, + ); + const x0: number = f0(3, 4); // -(3^4) + 1 + const x1: number = f1(3, 4); // -(3^4) + 1 + const x2: number = f2(3, 4); // -(3^4) + 1 + const x3: number = f3(3, 4); // -(3^4) + 1 + const x4: number = f4(3, 4); // -(3^4) + 1 + const x5: number = f5(3, 4); // -(3^4) + 1 +}; + +() => { + function fn(a: string, b: number, c: string) { + return [a, b, c]; + } + + const gn = R.compose( + R.length, + fn, + ); + const x: number = gn('Hello', 4, 'world'); +}; diff --git a/types/ramda/test/composeK-tests.ts b/types/ramda/test/composeK-tests.ts new file mode 100644 index 0000000000..cdde4586bd --- /dev/null +++ b/types/ramda/test/composeK-tests.ts @@ -0,0 +1,36 @@ +import * as R from 'ramda'; + +() => { + const get = (prop: string) => (obj: any): any[] => { + const propVal = obj[prop]; + if (propVal) { + return [propVal]; + } else { + return []; + } + }; + + const getStateCode: (input: any) => any[] = R.composeK( + R.compose( + val => [val], + R.toUpper, + ), + get('state'), + get('address'), + get('user'), + ); + getStateCode({ user: { address: { state: 'ny' } } }); // => [] + getStateCode({}); // => [] + + const nextThree = (num: number): number[] => [num, num + 1, num + 2]; + const onlyOverNine = (num: number): number[] => (num > 9 ? [num] : []); + const toString = (input: any): string[] => [`${input}`]; + const split = (input: string): string[] => input.split(''); + + const composed: (num: number) => string[] = R.composeK( + split, + toString, + onlyOverNine, + nextThree, + ); +}; diff --git a/types/ramda/test/composeP-tests.ts b/types/ramda/test/composeP-tests.ts new file mode 100644 index 0000000000..5012a91b72 --- /dev/null +++ b/types/ramda/test/composeP-tests.ts @@ -0,0 +1,36 @@ +import * as R from 'ramda'; + +() => { + interface User { + name: string; + followers: string[]; + } + interface Db { + users: { [index: string]: User }; + } + const db: Db = { + users: { + JOE: { + name: 'Joe', + followers: ['STEVE', 'SUZY'], + }, + }, + }; + + // We'll pretend to do a db lookup which returns a promise + const lookupUser = (userId: string): Promise => + Promise.resolve(db.users[userId]); + const lookupFollowers = (user: User): Promise => + Promise.resolve(user.followers); + lookupUser('JOE').then(lookupFollowers); + + // followersForUser :: String -> Promise [UserId] + const followersForUser: (input: string) => Promise = R.composeP( + lookupFollowers, + lookupUser, + ); + followersForUser('JOE').then(followers => + console.log('Followers:', followers), + ); + // Followers: ["STEVE","SUZY"] +}; diff --git a/types/ramda/test/composeWith-tests.ts b/types/ramda/test/composeWith-tests.ts new file mode 100644 index 0000000000..8460f5ee66 --- /dev/null +++ b/types/ramda/test/composeWith-tests.ts @@ -0,0 +1,42 @@ +import * as R from 'ramda'; + +() => { + const get = (prop: string) => (obj: any): any[] => { + const propVal = obj[prop]; + if (propVal) { + return [propVal]; + } else { + return []; + } + }; + + const getStateCode: (input: any) => any[] = R.composeWith(R.chain, [ + R.compose( + val => [val], + R.toUpper, + ), + get('state'), + get('address'), + get('user'), + ]); + getStateCode({ user: { address: { state: 'ny' } } }); // => [] + getStateCode({}); // => [] + + const nextThree = (num: number): number[] => [num, num + 1, num + 2]; + const onlyOverNine = (num: number): number[] => (num > 9 ? [num] : []); + const toString = (input: any): string[] => [`${input}`]; + const split = (input: string): string[] => input.split(''); + + const composed: (num: number) => string[] = R.composeWith(R.chain, [ + split, + toString, + onlyOverNine, + nextThree, + ]); + const composed2: (num: number) => string[] = R.composeWith(R.chain)([ + split, + toString, + onlyOverNine, + nextThree, + ]); +}; diff --git a/types/ramda/test/concat-tests.ts b/types/ramda/test/concat-tests.ts new file mode 100644 index 0000000000..9b177b4c6b --- /dev/null +++ b/types/ramda/test/concat-tests.ts @@ -0,0 +1,8 @@ +import * as R from 'ramda'; + +() => { + R.concat([], []); // => [] + R.concat([4, 5, 6], [1, 2, 3]); // => [4, 5, 6, 1, 2, 3] + R.concat([4, 5, 6])([1, 2, 3]); // => [4, 5, 6, 1, 2, 3] + R.concat('ABC')('DEF'); // 'ABCDEF' +}; diff --git a/types/ramda/test/cond-tests.ts b/types/ramda/test/cond-tests.ts new file mode 100644 index 0000000000..ac051d71ac --- /dev/null +++ b/types/ramda/test/cond-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +() => { + const f = R.cond([ + [x => x === 0, () => 'a'], + [() => true, () => 'b'], + ]); + f(0); // $ExpectType string + f(''); // $ExpectError + f(1, 2); // $ExpectType string + + const g = R.cond([[(a, b) => a === b, () => 'a'], [() => true, () => 'b']]); + g(0); + g(''); + g(1, ''); +}; diff --git a/types/ramda/test/construct-tests.ts b/types/ramda/test/construct-tests.ts new file mode 100644 index 0000000000..d4bf4a3004 --- /dev/null +++ b/types/ramda/test/construct-tests.ts @@ -0,0 +1,15 @@ +import * as R from 'ramda'; + +(() => { + function Circle(r: number, colors: string) { + this.r = r; + this.colors = colors; + } + + Circle.prototype.area = function() { + return Math.PI * Math.pow(this.r, 2); + }; + + const circle = R.construct(Circle); + circle(10, 'red'); +})(); diff --git a/types/ramda/test/constructN-tests.ts b/types/ramda/test/constructN-tests.ts new file mode 100644 index 0000000000..fbe400ef07 --- /dev/null +++ b/types/ramda/test/constructN-tests.ts @@ -0,0 +1,16 @@ +import * as R from 'ramda'; + +(() => { + function Circle(r: number, colors: string) { + this.r = r; + this.colors = colors; + } + + Circle.prototype.area = function() { + return Math.PI * Math.pow(this.r, 2); + }; + + const circleN = R.constructN(1, Circle); + circleN(10, 'red'); + circleN(10); +})(); diff --git a/types/ramda/test/contains-tests.ts b/types/ramda/test/contains-tests.ts new file mode 100644 index 0000000000..77a945f602 --- /dev/null +++ b/types/ramda/test/contains-tests.ts @@ -0,0 +1,10 @@ +import * as R from 'ramda'; + +() => { + R.contains(3)([1, 2, 3]); // => true + R.contains(3, [1, 2, 3]); // => true + R.contains(4)([1, 2, 3]); // => false + R.contains({})([{}, {}]); // => false + const obj = {}; + R.contains(obj)([{}, obj, {}]); // => true +}; diff --git a/types/ramda/test/converge-tests.ts b/types/ramda/test/converge-tests.ts new file mode 100644 index 0000000000..4b8b0429ca --- /dev/null +++ b/types/ramda/test/converge-tests.ts @@ -0,0 +1,42 @@ +import * as R from 'ramda'; + +() => { + const indentN = R.pipe( + R.times(R.always(' ')), + R.join(''), + R.replace(/^(?!$)/gm), + ); + + const format = R.converge(R.call, [ + R.pipe( + R.prop<'indent', number>('indent'), + indentN, + ), + R.prop('value'), + ]); + + format({ indent: 2, value: 'foo\nbar\nbaz\n' }); // => ' foo\n bar\n baz\n' +}; + +() => { + function add(a: number, b: number) { + return a + b; + } + + function multiply(a: number, b: number) { + return a * b; + } + + function subtract(a: number, b: number) { + return a - b; + } + + // ≅ multiply( add(1, 2), subtract(1, 2) ); + const x: number = R.converge(multiply, [add, subtract])(1, 2); // => -3 + + function add3(a: number, b: number, c: number) { + return a + b + c; + } + + const y: number = R.converge(add3, [multiply, add, subtract])(1, 2); // => 4 +}; diff --git a/types/ramda/tsconfig.json b/types/ramda/tsconfig.json index 72a115df8b..f439147a25 100644 --- a/types/ramda/tsconfig.json +++ b/types/ramda/tsconfig.json @@ -35,6 +35,24 @@ "test/apply-tests.ts", "test/applySpec-tests.ts", "test/assoc-tests.ts", - "test/assocPath-tests.ts" + "test/assocPath-tests.ts", + "test/binary-tests.ts", + "test/bind-tests.ts", + "test/both-tests.ts", + "test/chain-tests.ts", + "test/clamp-tests.ts", + "test/clone-tests.ts", + "test/comparator-tests.ts", + "test/complement-tests.ts", + "test/compose-tests.ts", + "test/composeK-tests.ts", + "test/composeP-tests.ts", + "test/composeWith-tests.ts", + "test/concat-tests.ts", + "test/cond-tests.ts", + "test/construct-tests.ts", + "test/constructN-tests.ts", + "test/contains-tests.ts", + "test/converge-tests.ts" ] } \ No newline at end of file