-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR #57393 [ramda] optimize compose, pipe, chain and othter fu…
…nctions. by @adispring * [ramda] optimize compose, pipe, chain and othter functions. * feat: optimize always and cond * feat: optimise composeWith, support multiple parameters * feat: optimize composeWith and pipeWith
- Loading branch information
Showing
16 changed files
with
247 additions
and
233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import * as R from 'ramda'; | ||
|
||
() => { | ||
// $ExpectType () => string | ||
const t = R.always('Tee'); | ||
// $ExpectType (...args: unknown[]) => string | ||
const alwaysTea = R.always('Tea'); | ||
// $ExpectType string | ||
const x: string = t(); // => 'Tee' | ||
alwaysTea(); // => 'Tea' | ||
|
||
// $ExpectType string | ||
alwaysTea('Coffee'); // => 'Tea' | ||
|
||
// $ExpectType string | ||
alwaysTea(1, 2, 3); // => 'Tea' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as R from 'ramda'; | ||
|
||
() => { | ||
const add = (a: number, b: number): number => a + b; | ||
|
||
// $ExpectType number | ||
const callAdd = R.call(add, 1, 2); | ||
|
||
// $ExpectError | ||
R.call(add, 'a', 2); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import * as R from 'ramda'; | ||
|
||
() => { | ||
const f = R.cond<number, string>([ | ||
const f = R.cond<[number], string>([ | ||
[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']]); | ||
// $ExpectType string | ||
f(0); | ||
|
||
// $ExpectError | ||
f(''); | ||
|
||
// $ExpectError | ||
f(1, 2); | ||
|
||
const g = R.cond([[(a: any, b: any): boolean => a === b, () => 'a'], [() => true, () => 'b']]); | ||
// $ExpectError | ||
g(0); | ||
|
||
// $ExpectError | ||
g(''); | ||
|
||
// $ExpectType string | ||
g(1, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import * as R from 'ramda'; | ||
|
||
() => { | ||
// $ExpectType (a: string) => string | ||
const truncate = R.when( | ||
R.propSatisfies(R.flip(R.gt)(10), 'length'), | ||
R.pipe<string, string, string[], string>( | ||
R.take(10), | ||
R.append('…') as (wrong: any) => string[], | ||
R.join(''), | ||
), | ||
(str: string) => str.length > 10, | ||
(str: string) => str.slice(0, 10) + '…', | ||
); | ||
const a: string = truncate('12345'); // => '12345' | ||
const b: string = truncate('0123456789ABC'); // => '0123456789…' | ||
|
||
const addOneIfNotNil = R.when( | ||
R.complement(R.isNil), | ||
// $ExpectType string | ||
truncate('12345'); // => '12345' | ||
// $ExpectType string | ||
truncate('0123456789ABC'); // => '0123456789…' | ||
|
||
// $ExpectType (a: number | undefined) => number | undefined | ||
const addOneIfNotNil = R.when<undefined | number, number>( | ||
x => x != null, | ||
R.add(1) | ||
); | ||
|
||
const nil: undefined = addOneIfNotNil(undefined); | ||
const two: number = addOneIfNotNil(1); | ||
// $ExpectType number | undefined | ||
const nil = addOneIfNotNil(undefined); | ||
// $ExpectType number | undefined | ||
const two = addOneIfNotNil(1); | ||
}; |
Oops, something went wrong.