mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[ramda] split tests to separate modules: 'remove' - 'take' (#45736)
* move 'remove' tests to separate file * move 'repeat' tests to separate file * move 'replace' tests to separate file * move 'reverse' tests to separate file * move 'scan' tests to separate file * move 'set' tests to separate file * move 'slice' tests to separate file * move 'sort' tests to separate file * move 'sortBy' tests to separate file * move 'sortWith' tests to separate file * move 'splitAt' tests to separate file * move 'splitEvery' tests to separate file * move 'splitWhen' tests to separate file * move 'startsWith' tests to separate file * move 'subtract' tests to separate file * move 'sum' tests to separate file * move 'symmetricDifference' tests to separate file * move 'symmetricDifferenceWith' tests to separate file * move 'tail' tests to separate file * move 'take' tests to separate file
This commit is contained in:
parent
433cf7ea6f
commit
3e2903c5c7
@ -138,7 +138,6 @@ R.times(i, 5);
|
||||
}
|
||||
|
||||
R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3]
|
||||
R.take(2, [1, 2, 3, 4]); // => [1, 2]
|
||||
});
|
||||
(() => {
|
||||
function f(n: number): false | [number, number] {
|
||||
@ -156,88 +155,6 @@ R.times(i, 5);
|
||||
() => {
|
||||
const headLens = R.lensIndex(0);
|
||||
R.view(headLens, ["a", "b", "c"]); // => 'a'
|
||||
R.set(headLens, "x", ["a", "b", "c"]); // => ['x', 'b', 'c']
|
||||
};
|
||||
|
||||
() => {
|
||||
R.remove(2, 3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
R.remove(2, 3)([1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
R.remove(2)(3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.repeat("hi", 5); // => ['hi', 'hi', 'hi', 'hi', 'hi']
|
||||
const obj = {};
|
||||
const repeatedObjs = R.repeat(obj, 5); // => [{}, {}, {}, {}, {}]
|
||||
repeatedObjs[0] === repeatedObjs[1]; // => true
|
||||
};
|
||||
|
||||
() => {
|
||||
R.reverse([1, 2, 3]); // => [3, 2, 1]
|
||||
R.reverse([1, 2]); // => [2, 1]
|
||||
R.reverse([1]); // => [1]
|
||||
R.reverse([]); // => []
|
||||
};
|
||||
|
||||
() => {
|
||||
R.reverse('abc'); // => 'cba'
|
||||
R.reverse('ab'); // => 'ba'
|
||||
R.reverse('a'); // => 'a'
|
||||
R.reverse(''); // => ''
|
||||
};
|
||||
|
||||
() => {
|
||||
const numbers = [1, 2, 3, 4];
|
||||
R.scan(R.multiply, 1, numbers); // => [1, 1, 2, 6, 24]
|
||||
R.scan(R.multiply, 1)(numbers); // => [1, 1, 2, 6, 24]
|
||||
R.scan(R.multiply)(1, numbers); // => [1, 1, 2, 6, 24]
|
||||
};
|
||||
|
||||
() => {
|
||||
const xs = R.range(0, 10);
|
||||
R.slice(2, 5, xs); // => [2, 3, 4]
|
||||
R.slice(2, 5)(xs); // => [2, 3, 4]
|
||||
R.slice(2)(5, xs); // => [2, 3, 4]
|
||||
|
||||
const str = "Hello World";
|
||||
R.slice(2, 5, str); // => 'llo'
|
||||
R.slice(2, 5)(str); // => 'llo'
|
||||
R.slice(2)(5, str); // => 'llo'
|
||||
};
|
||||
|
||||
() => {
|
||||
function diff(a: number, b: number) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
R.sort(diff, [4, 2, 7, 5]); // => [2, 4, 5, 7]
|
||||
R.sort(diff)([4, 2, 7, 5]); // => [2, 4, 5, 7]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.tail(["fi", "fo", "fum"]); // => ['fo', 'fum']
|
||||
R.tail([1, 2, 3]); // => [2, 3]
|
||||
R.tail("abc"); // => 'bc'
|
||||
R.tail(""); // => ''
|
||||
};
|
||||
|
||||
() => {
|
||||
R.take(3, [1, 2, 3, 4, 5]); // => [1,2,3]
|
||||
|
||||
const members = ["Paul Desmond", "Bob Bates", "Joe Dodge", "Ron Crotty", "Lloyd Davis", "Joe Morello", "Norman Bates",
|
||||
"Eugene Wright", "Gerry Mulligan", "Jack Six", "Alan Dawson", "Darius Brubeck", "Chris Brubeck",
|
||||
"Dan Brubeck", "Bobby Militello", "Michael Moore", "Randy Jones"];
|
||||
const takeFive = R.take(5);
|
||||
|
||||
// $ExpectType string[]
|
||||
takeFive(members); // => ["Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis"]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.take(3, "Example"); // => "Exa"
|
||||
|
||||
const takeThree = R.take(3);
|
||||
takeThree("Example"); // => "Exa"
|
||||
};
|
||||
|
||||
() => {
|
||||
@ -396,21 +313,16 @@ R.times(i, 5);
|
||||
const xLens = R.lens(R.prop("x"), R.assoc("x"));
|
||||
R.view(xLens, {x: 1, y: 2}); // => 1
|
||||
R.view(xLens)({x: 1, y: 2}); // => 1
|
||||
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}
|
||||
};
|
||||
|
||||
() => {
|
||||
const headLens = R.lensIndex(0);
|
||||
R.view(headLens, ["a", "b", "c"]); // => 'a'
|
||||
R.set(headLens, "x", ["a", "b", "c"]); // => ['x', '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}
|
||||
};
|
||||
|
||||
() => {
|
||||
@ -418,7 +330,6 @@ R.times(i, 5);
|
||||
const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]};
|
||||
|
||||
R.view(xyLens, testObj); // => 2
|
||||
R.set(xyLens, 4, testObj); // => {x: [{y: 4, z: 3}, {y: 4, z: 5}]}
|
||||
};
|
||||
|
||||
() => {
|
||||
@ -485,136 +396,6 @@ R.times(i, 5);
|
||||
const a: number[] = R.without([1, 2], [1, 2, 1, 3, 4]); // => [3, 4]
|
||||
};
|
||||
|
||||
() => {
|
||||
const people = [
|
||||
{name: 'Agy', age: 33}, {name: 'Bib', age: 15}, {name: 'Cari', age: 16}
|
||||
];
|
||||
|
||||
R.sortWith([R.ascend(R.prop('age')), R.descend(R.prop('name'))], people);
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* Relation category
|
||||
*/
|
||||
() => {
|
||||
const sortByAgeDescending = R.sortBy(R.compose<{}, number, number>(R.negate, R.prop("age")));
|
||||
const alice = {
|
||||
name: "ALICE",
|
||||
age : 101
|
||||
};
|
||||
const bob = {
|
||||
name: "Bob",
|
||||
age : -10
|
||||
};
|
||||
const clara = {
|
||||
name: "clara",
|
||||
age : 314.159
|
||||
};
|
||||
const people = [clara, bob, alice];
|
||||
sortByAgeDescending(people); // => [alice, bob, clara]
|
||||
};
|
||||
|
||||
() => {
|
||||
const sortByNameCaseInsensitive = R.sortBy(R.compose<Record<'name', string>, string, string>(R.toLower, R.prop("name")));
|
||||
const alice = {
|
||||
name: "ALICE",
|
||||
age : 101
|
||||
};
|
||||
const bob = {
|
||||
name: "Bob",
|
||||
age : -10
|
||||
};
|
||||
const clara = {
|
||||
name: "clara",
|
||||
age : 314.159
|
||||
};
|
||||
const people = [clara, bob, alice];
|
||||
sortByNameCaseInsensitive(people); // => [alice, bob, clara]
|
||||
};
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitAt(1, [1, 2, 3]); // => [[1], [2, 3]]
|
||||
const b: number[][] = R.splitAt(1)([1, 2, 3]); // => [[1], [2, 3]]
|
||||
const c: string[] = R.splitAt(5, "hello world"); // => ['hello', ' world']
|
||||
const d: string[] = R.splitAt(-1, "foobar"); // => ['fooba', 'r']
|
||||
const e: string[] = R.splitAt(-1)("foobar"); // => ['fooba', 'r']
|
||||
};
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]]
|
||||
const b: number[][] = R.splitEvery(3)([1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]]
|
||||
const c: string[] = R.splitEvery(3, 'foobarbaz'); // => ['foo', 'bar', 'baz']
|
||||
const d: string[] = R.splitEvery(3)('foobarbaz'); // => ['foo', 'bar', 'baz']
|
||||
};
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]]
|
||||
const b: number[][] = R.splitWhen(R.equals(2))([1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.startsWith("a", "abc"); // => true
|
||||
R.startsWith("a")("abc"); // => true
|
||||
R.startsWith(1, [1, 2, 3]); // => true
|
||||
R.startsWith(1)([1, 2, 3]); // => true
|
||||
R.startsWith([1], [1, 2, 3]); // => true
|
||||
R.startsWith([1])([1, 2, 3]); // => true
|
||||
};
|
||||
|
||||
() => {
|
||||
R.subtract(10, 8); // => 2
|
||||
|
||||
const complementaryAngle = R.subtract(90);
|
||||
complementaryAngle(30); // => 60
|
||||
complementaryAngle(72); // => 18
|
||||
};
|
||||
|
||||
() => {
|
||||
R.sum([2, 4, 6, 8, 100, 1]); // => 121
|
||||
};
|
||||
|
||||
() => {
|
||||
const a: number[] = R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2,7,6,5]
|
||||
const b: number[] = R.symmetricDifference([7, 6, 5, 4, 3])([1, 2, 3, 4]); // => [7,6,5,1,2]
|
||||
};
|
||||
|
||||
() => {
|
||||
const eqA = R.eqBy(R.prop("a"));
|
||||
const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}];
|
||||
const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}];
|
||||
R.symmetricDifferenceWith(eqA, l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
R.symmetricDifferenceWith(eqA)(l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
// const c: (a: any[]) => any[] = R.symmetricDifferenceWith(eqA)(l1); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
};
|
||||
|
||||
() => {
|
||||
const eqL = R.eqBy<string, number>(s => s.length);
|
||||
const l1 = ['bb', 'ccc', 'dddd'];
|
||||
const l2 = ['aaa', 'bb', 'c'];
|
||||
R.symmetricDifferenceWith(eqL, l1, l2); // => ['dddd', 'c']
|
||||
R.symmetricDifferenceWith(eqL)(l1, l2); // => ['dddd', 'c']
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* String category
|
||||
*/
|
||||
() => {
|
||||
R.replace("foo", "bar", "foo foo foo"); // => 'bar foo foo'
|
||||
R.replace("foo", "bar")("foo foo foo"); // => 'bar foo foo'
|
||||
R.replace("foo")("bar")("foo foo foo"); // => 'bar foo foo'
|
||||
R.replace(/foo/, "bar", "foo foo foo"); // => 'bar foo foo'
|
||||
|
||||
// Use the "g" (global) flag to replace all occurrences:
|
||||
R.replace(/foo/g, "bar", "foo foo foo"); // => 'bar bar bar'
|
||||
R.replace(/foo/g, "bar")("foo foo foo"); // => 'bar bar bar'
|
||||
R.replace(/foo/g)("bar")("foo foo foo"); // => 'bar bar bar'
|
||||
|
||||
// Using a function as the replacement value
|
||||
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'
|
||||
R.replace(/([cfk])oo/g)((match, p1, offset) => `${p1}-${offset}`) ("coo foo koo"); // => 'c0oo f4oo k8oo'
|
||||
};
|
||||
|
||||
() => {
|
||||
interface A {
|
||||
a: number;
|
||||
|
||||
7
types/ramda/test/remove-tests.ts
Normal file
7
types/ramda/test/remove-tests.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.remove(2, 3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
R.remove(2, 3)([1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
R.remove(2)(3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8]
|
||||
};
|
||||
8
types/ramda/test/repeat-tests.ts
Normal file
8
types/ramda/test/repeat-tests.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.repeat('hi', 5); // => ['hi', 'hi', 'hi', 'hi', 'hi']
|
||||
const obj = {};
|
||||
const repeatedObjs = R.repeat(obj, 5); // => [{}, {}, {}, {}, {}]
|
||||
repeatedObjs[0] === repeatedObjs[1]; // => true
|
||||
};
|
||||
26
types/ramda/test/replace-tests.ts
Normal file
26
types/ramda/test/replace-tests.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.replace('foo', 'bar', 'foo foo foo'); // => 'bar foo foo'
|
||||
R.replace('foo', 'bar')('foo foo foo'); // => 'bar foo foo'
|
||||
R.replace('foo')('bar')('foo foo foo'); // => 'bar foo foo'
|
||||
R.replace(/foo/, 'bar', 'foo foo foo'); // => 'bar foo foo'
|
||||
|
||||
// Use the "g" (global) flag to replace all occurrences:
|
||||
R.replace(/foo/g, 'bar', 'foo foo foo'); // => 'bar bar bar'
|
||||
R.replace(/foo/g, 'bar')('foo foo foo'); // => 'bar bar bar'
|
||||
R.replace(/foo/g)('bar')('foo foo foo'); // => 'bar bar bar'
|
||||
|
||||
// Using a function as the replacement value
|
||||
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'
|
||||
R.replace(/([cfk])oo/g)((match, p1, offset) => `${p1}-${offset}`)(
|
||||
'coo foo koo',
|
||||
); // => 'c0oo f4oo k8oo'
|
||||
};
|
||||
15
types/ramda/test/reverse-tests.ts
Normal file
15
types/ramda/test/reverse-tests.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.reverse([1, 2, 3]); // => [3, 2, 1]
|
||||
R.reverse([1, 2]); // => [2, 1]
|
||||
R.reverse([1]); // => [1]
|
||||
R.reverse([]); // => []
|
||||
};
|
||||
|
||||
() => {
|
||||
R.reverse('abc'); // => 'cba'
|
||||
R.reverse('ab'); // => 'ba'
|
||||
R.reverse('a'); // => 'a'
|
||||
R.reverse(''); // => ''
|
||||
};
|
||||
8
types/ramda/test/scan-tests.ts
Normal file
8
types/ramda/test/scan-tests.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const numbers = [1, 2, 3, 4];
|
||||
R.scan(R.multiply, 1, numbers); // => [1, 1, 2, 6, 24]
|
||||
R.scan(R.multiply, 1)(numbers); // => [1, 1, 2, 6, 24]
|
||||
R.scan(R.multiply)(1, numbers); // => [1, 1, 2, 6, 24]
|
||||
};
|
||||
30
types/ramda/test/set-tests.ts
Normal file
30
types/ramda/test/set-tests.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const headLens = R.lensIndex(0);
|
||||
R.set(headLens, 'x', ['a', 'b', 'c']); // => ['x', 'b', 'c']
|
||||
};
|
||||
|
||||
() => {
|
||||
const xLens = R.lens(R.prop('x'), R.assoc('x'));
|
||||
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}
|
||||
};
|
||||
|
||||
() => {
|
||||
const headLens = R.lensIndex(0);
|
||||
R.set(headLens, 'x', ['a', 'b', 'c']); // => ['x', 'b', 'c']
|
||||
};
|
||||
|
||||
() => {
|
||||
const xLens = R.lensProp('x');
|
||||
R.set(xLens, 4, { x: 1, y: 2 }); // => {x: 4, y: 2}
|
||||
};
|
||||
|
||||
() => {
|
||||
const xyLens = R.lensPath(['x', 0, 'y']);
|
||||
const testObj = { x: [{ y: 2, z: 3 }, { y: 4, z: 5 }] };
|
||||
|
||||
R.set(xyLens, 4, testObj); // => {x: [{y: 4, z: 3}, {y: 4, z: 5}]}
|
||||
};
|
||||
13
types/ramda/test/slice-tests.ts
Normal file
13
types/ramda/test/slice-tests.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const xs = R.range(0, 10);
|
||||
R.slice(2, 5, xs); // => [2, 3, 4]
|
||||
R.slice(2, 5)(xs); // => [2, 3, 4]
|
||||
R.slice(2)(5, xs); // => [2, 3, 4]
|
||||
|
||||
const str = 'Hello World';
|
||||
R.slice(2, 5, str); // => 'llo'
|
||||
R.slice(2, 5)(str); // => 'llo'
|
||||
R.slice(2)(5, str); // => 'llo'
|
||||
};
|
||||
10
types/ramda/test/sort-tests.ts
Normal file
10
types/ramda/test/sort-tests.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
function diff(a: number, b: number) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
R.sort(diff, [4, 2, 7, 5]); // => [2, 4, 5, 7]
|
||||
R.sort(diff)([4, 2, 7, 5]); // => [2, 4, 5, 7]
|
||||
};
|
||||
47
types/ramda/test/sortBy-tests.ts
Normal file
47
types/ramda/test/sortBy-tests.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const sortByAgeDescending = R.sortBy(
|
||||
R.compose<{}, number, number>(
|
||||
R.negate,
|
||||
R.prop('age'),
|
||||
),
|
||||
);
|
||||
const alice = {
|
||||
name: 'ALICE',
|
||||
age: 101,
|
||||
};
|
||||
const bob = {
|
||||
name: 'Bob',
|
||||
age: -10,
|
||||
};
|
||||
const clara = {
|
||||
name: 'clara',
|
||||
age: 314.159,
|
||||
};
|
||||
const people = [clara, bob, alice];
|
||||
sortByAgeDescending(people); // => [alice, bob, clara]
|
||||
};
|
||||
|
||||
() => {
|
||||
const sortByNameCaseInsensitive = R.sortBy(
|
||||
R.compose<Record<'name', string>, string, string>(
|
||||
R.toLower,
|
||||
R.prop('name'),
|
||||
),
|
||||
);
|
||||
const alice = {
|
||||
name: 'ALICE',
|
||||
age: 101,
|
||||
};
|
||||
const bob = {
|
||||
name: 'Bob',
|
||||
age: -10,
|
||||
};
|
||||
const clara = {
|
||||
name: 'clara',
|
||||
age: 314.159,
|
||||
};
|
||||
const people = [clara, bob, alice];
|
||||
sortByNameCaseInsensitive(people); // => [alice, bob, clara]
|
||||
};
|
||||
11
types/ramda/test/sortWith-tests.ts
Normal file
11
types/ramda/test/sortWith-tests.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const people = [
|
||||
{ name: 'Agy', age: 33 },
|
||||
{ name: 'Bib', age: 15 },
|
||||
{ name: 'Cari', age: 16 },
|
||||
];
|
||||
|
||||
R.sortWith([R.ascend(R.prop('age')), R.descend(R.prop('name'))], people);
|
||||
};
|
||||
9
types/ramda/test/splitAt-tests.ts
Normal file
9
types/ramda/test/splitAt-tests.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitAt(1, [1, 2, 3]); // => [[1], [2, 3]]
|
||||
const b: number[][] = R.splitAt(1)([1, 2, 3]); // => [[1], [2, 3]]
|
||||
const c: string[] = R.splitAt(5, 'hello world'); // => ['hello', ' world']
|
||||
const d: string[] = R.splitAt(-1, 'foobar'); // => ['fooba', 'r']
|
||||
const e: string[] = R.splitAt(-1)('foobar'); // => ['fooba', 'r']
|
||||
};
|
||||
8
types/ramda/test/splitEvery-tests.ts
Normal file
8
types/ramda/test/splitEvery-tests.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]]
|
||||
const b: number[][] = R.splitEvery(3)([1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]]
|
||||
const c: string[] = R.splitEvery(3, 'foobarbaz'); // => ['foo', 'bar', 'baz']
|
||||
const d: string[] = R.splitEvery(3)('foobarbaz'); // => ['foo', 'bar', 'baz']
|
||||
};
|
||||
6
types/ramda/test/splitWhen-tests.ts
Normal file
6
types/ramda/test/splitWhen-tests.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const a: number[][] = R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]]
|
||||
const b: number[][] = R.splitWhen(R.equals(2))([1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]]
|
||||
};
|
||||
10
types/ramda/test/startsWith-tests.ts
Normal file
10
types/ramda/test/startsWith-tests.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.startsWith('a', 'abc'); // => true
|
||||
R.startsWith('a')('abc'); // => true
|
||||
R.startsWith(1, [1, 2, 3]); // => true
|
||||
R.startsWith(1)([1, 2, 3]); // => true
|
||||
R.startsWith([1], [1, 2, 3]); // => true
|
||||
R.startsWith([1])([1, 2, 3]); // => true
|
||||
};
|
||||
9
types/ramda/test/subtract-tests.ts
Normal file
9
types/ramda/test/subtract-tests.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.subtract(10, 8); // => 2
|
||||
|
||||
const complementaryAngle = R.subtract(90);
|
||||
complementaryAngle(30); // => 60
|
||||
complementaryAngle(72); // => 18
|
||||
};
|
||||
5
types/ramda/test/sum-tests.ts
Normal file
5
types/ramda/test/sum-tests.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.sum([2, 4, 6, 8, 100, 1]); // => 121
|
||||
};
|
||||
6
types/ramda/test/symmetricDifference-tests.ts
Normal file
6
types/ramda/test/symmetricDifference-tests.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const a: number[] = R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2,7,6,5]
|
||||
const b: number[] = R.symmetricDifference([7, 6, 5, 4, 3])([1, 2, 3, 4]); // => [7,6,5,1,2]
|
||||
};
|
||||
20
types/ramda/test/symmetricDifferenceWith-tests.ts
Normal file
20
types/ramda/test/symmetricDifferenceWith-tests.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
const eqA = R.eqBy(R.prop('a'));
|
||||
const l1 = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }];
|
||||
const l2 = [{ a: 3 }, { a: 4 }, { a: 5 }, { a: 6 }];
|
||||
R.symmetricDifferenceWith(eqA, l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
R.symmetricDifferenceWith(eqA)(l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
// The below test is commented because it hits the type instantiation limit:
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/37839
|
||||
// const c: (a: any[]) => any[] = R.symmetricDifferenceWith(eqA)(l1); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
|
||||
};
|
||||
|
||||
() => {
|
||||
const eqL = R.eqBy<string, number>(s => s.length);
|
||||
const l1 = ['bb', 'ccc', 'dddd'];
|
||||
const l2 = ['aaa', 'bb', 'c'];
|
||||
R.symmetricDifferenceWith(eqL, l1, l2); // => ['dddd', 'c']
|
||||
R.symmetricDifferenceWith(eqL)(l1, l2); // => ['dddd', 'c']
|
||||
};
|
||||
8
types/ramda/test/tail-tests.ts
Normal file
8
types/ramda/test/tail-tests.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.tail(['fi', 'fo', 'fum']); // => ['fo', 'fum']
|
||||
R.tail([1, 2, 3]); // => [2, 3]
|
||||
R.tail('abc'); // => 'bc'
|
||||
R.tail(''); // => ''
|
||||
};
|
||||
40
types/ramda/test/take-tests.ts
Normal file
40
types/ramda/test/take-tests.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as R from 'ramda';
|
||||
|
||||
() => {
|
||||
R.take(2, [1, 2, 3, 4]); // => [1, 2]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.take(3, [1, 2, 3, 4, 5]); // => [1,2,3]
|
||||
|
||||
const members = [
|
||||
'Paul Desmond',
|
||||
'Bob Bates',
|
||||
'Joe Dodge',
|
||||
'Ron Crotty',
|
||||
'Lloyd Davis',
|
||||
'Joe Morello',
|
||||
'Norman Bates',
|
||||
'Eugene Wright',
|
||||
'Gerry Mulligan',
|
||||
'Jack Six',
|
||||
'Alan Dawson',
|
||||
'Darius Brubeck',
|
||||
'Chris Brubeck',
|
||||
'Dan Brubeck',
|
||||
'Bobby Militello',
|
||||
'Michael Moore',
|
||||
'Randy Jones',
|
||||
];
|
||||
const takeFive = R.take(5);
|
||||
|
||||
// $ExpectType string[]
|
||||
takeFive(members); // => ["Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis"]
|
||||
};
|
||||
|
||||
() => {
|
||||
R.take(3, 'Example'); // => "Exa"
|
||||
|
||||
const takeThree = R.take(3);
|
||||
takeThree('Example'); // => "Exa"
|
||||
};
|
||||
@ -191,6 +191,26 @@
|
||||
"test/reduceBy-tests.ts",
|
||||
"test/reduceRight-tests.ts",
|
||||
"test/reduceWhile-tests.ts",
|
||||
"test/reject-tests.ts"
|
||||
"test/reject-tests.ts",
|
||||
"test/remove-tests.ts",
|
||||
"test/repeat-tests.ts",
|
||||
"test/replace-tests.ts",
|
||||
"test/reverse-tests.ts",
|
||||
"test/scan-tests.ts",
|
||||
"test/set-tests.ts",
|
||||
"test/slice-tests.ts",
|
||||
"test/sort-tests.ts",
|
||||
"test/sortBy-tests.ts",
|
||||
"test/sortWith-tests.ts",
|
||||
"test/splitAt-tests.ts",
|
||||
"test/splitEvery-tests.ts",
|
||||
"test/splitWhen-tests.ts",
|
||||
"test/startsWith-tests.ts",
|
||||
"test/subtract-tests.ts",
|
||||
"test/sum-tests.ts",
|
||||
"test/symmetricDifference-tests.ts",
|
||||
"test/symmetricDifferenceWith-tests.ts",
|
||||
"test/tail-tests.ts",
|
||||
"test/take-tests.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user