🤖 Merge PR #47763 [ramda] R.when does not always apply given function by @JalilArfaoui

This commit is contained in:
Jalil Arfaoui 2020-09-24 08:46:06 +02:00 committed by GitHub
parent e98fe25b32
commit f8b43fbb7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -2082,8 +2082,8 @@ export function view<T, U>(lens: Lens, obj: T): U;
* will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied,
* the argument is returned as is.
*/
export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U;
export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U;
export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): T | U;
export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => T | U;
/**
* Takes a spec object and a test object and returns true if the test satisfies the spec.

View File

@ -11,4 +11,12 @@ import * as R from 'ramda';
);
const a: string = truncate('12345'); // => '12345'
const b: string = truncate('0123456789ABC'); // => '0123456789…'
const addOneIfNotNil = R.when(
R.complement(R.isNil),
R.add(1)
);
const nil: undefined = addOneIfNotNil(undefined);
const two: number = addOneIfNotNil(1);
};