types-ramda
Version:
Dedicated types library for ramda
1,450 lines (1,344 loc) • 242 kB
TypeScript
import * as _ from 'ts-toolbelt';
import {
DeepModify,
} from './deepModify';
import {
AtLeastOneFunctionsFlow,
AtLeastOneFunctionsFlowFromRightToLeft,
CondPair,
CondPairTypeguard,
DefaultTo,
Evolvable,
Evolve,
Evolver,
Falsy,
Functor,
FunctorMap,
FunctorFantasyLand,
InferAnyAType,
KeyValuePair,
Lens,
InferAllAType,
mergeArrWithLeft,
LargestArgumentsList,
IfFunctionsArgumentsDoNotOverlap,
ObjPred,
Ord,
LT,
EQ,
GT,
Ordering,
ObjectHavingSome,
PartialRecord,
Path,
Placeholder,
Reduced,
Fn,
ReturnTypesOfFns,
InputTypesOfFns,
ValueOfUnion,
Take,
Tuple,
ToTupleOfArray,
ToTupleOfFunction,
Prop,
WidenLiterals,
ElementOf,
NonEmptyArray,
ReadonlyNonEmptyArray,
Prettify,
Remap,
} from './tools';
import {
_ZipObj,
} from './zipObj';
/**
* Returns a partial copy of an object omitting the keys specified.
*
* See also {@link pick}
*
* @example
* ```typescript
* R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
* ```
*/
export function omit<Keys extends readonly PropertyKey[]>(names: Keys): <U extends Partial<Record<ElementOf<Keys>, any>>>(obj: ElementOf<Keys> extends keyof U ? U : never) => ElementOf<Keys> extends keyof U ? Omit<U, ElementOf<Keys>> : never;
export function omit<U, Keys extends keyof U>(names: readonly Keys[], obj: U): Omit<U, Keys>;
/**
* Returns a partial copy of an object containing only the keys specified. If
* the key does not exist, the property is ignored.
*
* See also {@link omit}, {@link props}
*
* @example
* ```typescript
* R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
* R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
* ```
*/
export function pick<Keys extends readonly PropertyKey[]>(names: Keys): <U extends Partial<Record<ElementOf<Keys>, any>>>(obj: ElementOf<Keys> extends keyof U ? U : never) => ElementOf<Keys> extends keyof U ? Pick<U, ElementOf<Keys>> : never;
export function pick<U, Keys extends keyof U>(names: readonly Keys[], obj: U): Pick<U, Keys>;
/**
* A special placeholder value used to specify "gaps" within curried functions,
* allowing partial application of any combination of arguments, regardless of
* their positions.
*
* If `g` is a curried ternary function and `_` is `R.__`, the following are
* equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2, _)(1, 3)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @example
* ```typescript
* const greet = R.replace('{name}', R.__, 'Hello, {name}!');
* greet('Alice'); //=> 'Hello, Alice!'
* ```
*/
export const __: Placeholder;
/**
* Adds two values.
*
* See also {@link subtract}
*
* @example
* ```typescript
* R.add(2, 3); //=> 5
* R.add(7)(10); //=> 17
* ```
*/
export function add(a: number): (b: number) => number;
export function add(a: number, b: number): number;
/**
* Creates a new list iteration function from an existing one by adding two new
* parameters to its callback function: the current index, and the entire list.
*
* This would turn, for instance, [`R.map`](#map) function into one that
* more closely resembles `Array.prototype.map`. Note that this will only work
* for functions in which the iteration callback function is the first
* parameter, and where the list is the last parameter. (This latter might be
* unimportant if the list parameter is not used.)
*
* @example
* ```typescript
* const mapIndexed = R.addIndex(R.map);
* mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
* //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
* ```
*/
export function addIndex<T>(
fn: (f: (item: T) => void, list: readonly T[]) => T[],
): _.F.Curry<(a: (item: T, idx: number, list: T[]) => void, b: readonly T[]) => T[]>;
// Special case for filter
export function addIndex<T>(
fn: (f: (item: T) => boolean, list: readonly T[]) => T[],
): _.F.Curry<(a: (item: T, idx: number, list: T[]) => boolean, b: readonly T[]) => T[]>;
// Special case for map
export function addIndex<T, U>(
fn: (f: (item: T) => U, list: readonly T[]) => U[],
): _.F.Curry<(a: (item: T, idx: number, list: T[]) => U, b: readonly T[]) => U[]>;
// Special case for reduce
export function addIndex<T, U>(
fn: (f: (acc: U, item: T) => U, aci: U, list: readonly T[]) => U,
): _.F.Curry<(a: (acc: U, item: T, idx: number, list: T[]) => U, b: U, c: readonly T[]) => U>;
/**
* Applies a function to the value at the given index of an array, returning a
* new copy of the array with the element at the given index replaced with the
* result of the function application.
*
* When `idx < -list.length || idx >= list.length`, the original list is returned.
*
* See also {@link update}
*
* @example
* ```typescript
* R.adjust(1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'B', 'c', 'd']
* R.adjust(-1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'D']
*
* // out-of-range returns original list
* R.adjust(4, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'd']
* R.adjust(-5, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'd']
* ```
*/
export function adjust(index: number): {
// adjust(index)(fn, list)
<T>(fn: (a: T) => T, list: readonly T[]): T[];
// adjust(index)(__, list)(fn)
<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => T) => T[];
// adjust(index)(fn)(list)
<T>(fn: (a: T) => T): (list: readonly T[]) => T[];
};
// adjust(__, fn)
export function adjust<T>(__: Placeholder, fn: (a: T) => T): {
// adjust(__, fn)(list)(index)
(list: readonly T[]): (index: number) => T[];
// adjust(__, fn)(__, index)(list)
(__: Placeholder, index: number): (list: readonly T[]) => T[];
// adjust(__, fn)(list, index)
(list: readonly T[], index: number): T[];
};
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
// adjust(index, fn)(list)
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
// adjust(index, fn)(list)
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
// adjust(__, __, list)
export function adjust<T>(__: Placeholder, __2: Placeholder, list: readonly T[]): {
// adjust(__, __, list)(index)(fn)
(index: number): (fn: (a: T) => T) => T[];
// adjust(__, __, list)(__, fn)(index)
(__3: Placeholder, fn: (a: T) => T): (index: number) => T[];
// adjust(__, __, list)(index, fn)
(index: number, fn: (a: T) => T): T[];
};
// adjust(index, __, list)(fn)
export function adjust<T>(index: number, __: Placeholder, list: readonly T[]): (fn: (a: T) => T) => T[];
// adjust(__, fn, list)(index)
export function adjust<T>(__: Placeholder, fn: (a: T) => T, list: readonly T[]): (index: number) => T[];
// adjust(index, fn, list)
export function adjust<T>(index: number, fn: (a: T) => T, list: readonly T[]): T[];
/**
* Returns `true` if all elements of the list match the predicate, `false` if
* there are any that don't.
*
* Dispatches to the `all` method of the second argument, if present.
*
* Acts as a transducer if a transformer is given in list position.
*
* See also {@link any}, {@link none}, {@link transduce}
*
* @example
* ```typescript
* const equals3 = R.equals(3);
* R.all(equals3)([3, 3, 3, 3]); //=> true
* R.all(equals3)([3, 3, 1, 3]); //=> false
* ```
*/
export function all<T>(fn: (a: T) => boolean): {
// all (fn)({ all })
<U extends { all: (fn: (a: T) => boolean) => boolean }>(obj: U): boolean;
// all (fn)(list)
(list: readonly T[]): boolean;
};
// all(__, { all })(fn)
export function all<U extends { all: (fn: (a: any) => boolean) => boolean }>(__: Placeholder, obj: U): (fn: (a: InferAllAType<U>) => boolean) => boolean;
// all(__, list)(fn)
export function all<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean;
// all(fn, { all })
export function all<T, U extends { all: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean;
// all(fn, list)
export function all<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
/**
* Takes a list of predicates and returns a predicate that returns true for a
* given list of arguments if every one of the provided predicates is satisfied
* by those arguments.
*
* The function returned is a curried function whose arity matches that of the
* highest-arity predicate.
*
* See also {@link anyPass}, {@link both}
*
* @example
* ```typescript
* const isQueen = R.propEq('Q', 'rank');
* const isSpade = R.propEq('♠︎', 'suit');
* const isQueenOfSpades = R.allPass([isQueen, isSpade]);
*
* isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
* isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true
* ```
*/
export function allPass<T, TF1 extends T, TF2 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2]
): (a: T) => a is TF1 & TF2;
export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2, (a: T) => a is TF3],
): (a: T) => a is TF1 & TF2 & TF3;
export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2, (a: T) => a is TF3, (a: T) => a is TF4],
): (a: T) => a is TF1 & TF2 & TF3 & TF4;
export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T>(
predicates: [
(a: T) => a is TF1,
(a: T) => a is TF2,
(a: T) => a is TF3,
(a: T) => a is TF4,
(a: T) => a is TF5
],
): (a: T) => a is TF1 & TF2 & TF3 & TF4 & TF5;
export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T>(
predicates: [
(a: T) => a is TF1,
(a: T) => a is TF2,
(a: T) => a is TF3,
(a: T) => a is TF4,
(a: T) => a is TF5,
(a: T) => a is TF6
],
): (a: T) => a is TF1 & TF2 & TF3 & TF4 & TF5 & TF6;
export function allPass<F extends (...args: any[]) => boolean>(predicates: readonly F[]): F;
/**
* Returns a function that always returns the given value. Note that for
* non-primitives the value returned is a reference to the original value.
*
* This function is known as `const`, `constant`, or `K` (for K combinator) in
* other languages and libraries.
*
* @example
* ```typescript
* const t = R.always('Tee');
* t(); //=> 'Tee'
* ```
*/
export function always<T>(val: T): (...args: unknown[]) => T;
/**
* Returns the first argument if it is falsy, otherwise the second argument.
* Acts as the boolean `and` statement if both inputs are `Boolean`s.
*
* See also {@link both}, {@link or}
*
* @example
* ```typescript
* R.and(true, true); //=> true
* R.and(true, false); //=> false
* R.and(false, true); //=> false
* R.and(false, false); //=> false
* ```
*/
export function and<A>(a: A): <B>(b: B) => A | B;
export function and<B>(__: Placeholder, b: B): <A>(a: A) => A | B;
export function and<A, B>(a: A, b: B): A | B;
/**
* Returns the result of applying the onSuccess function to the value inside
* a successfully resolved promise. This is useful for working with promises
* inside function compositions.
*
* See also {@link otherwise}, {@link pipeWith}
*
* @example
* ```typescript
* const makeQuery = email => ({ query: { email }});
* const fetchMember = request =>
* Promise.resolve({ firstName: 'Bob', lastName: 'Loblaw', id: 42 });
* const pickName = R.pick(['firstName', 'lastName'])
*
* //getMemberName :: String -> Promise ({ firstName, lastName })
* const getMemberName = R.pipe(
* makeQuery,
* fetchMember,
* R.andThen(pickName),
* );
*
* // Alternately
* const getMemberName = R.pipe(
* makeQuery,
* fetchMember,
* )
*
* R.pipeWith(R.andThen, [getMemberName, pickName])('bob@gmail.com').then(console.log)
* // logs {"firstName":"Bob","lastName":"Loblaw"}
*
* getMemberName('bob@gmail.com').then(console.log);
* ```
*/
export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>): (promise: Promise<A>) => Promise<B>;
export function andThen<A>(__: Placeholder, promise: Promise<A>): <B>(onSuccess: (a: A) => B | Promise<B>) => Promise<B>;
export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>, promise: Promise<A>): Promise<B>;
/**
* Returns `true` if at least one of the elements of the list match the predicate,
* `false` otherwise.
*
* Dispatches to the `any` method of the second argument, if present.
*
* Acts as a transducer if a transformer is given in list position.
*
* See also {@link all}, {@link none}, {@link transduce}
*
* @example
* ```typescript
* const lessThan0 = R.flip(R.lt)(0);
* const lessThan2 = R.flip(R.lt)(2);
* R.any(lessThan0)([1, 2]); //=> false
* R.any(lessThan2)([1, 2]); //=> true
* ```
*/
export function any<T>(fn: (a: T) => boolean): {
// any(fn)(list)
(list: readonly T[]): boolean;
// all (fn)({ any })
<U extends { any: (fn: (a: T) => boolean) => boolean }>(obj: U): boolean;
};
// any(__, list)(fn)
export function any<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean;
// any(__, { any })(fn)
export function any<U extends { any: (fn: (a: any) => boolean) => boolean }>(___: Placeholder, obj: U): (fn: (a: InferAnyAType<U>) => boolean) => boolean;
// any(fn, list)
export function any<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
// any(fn, { any })
export function any<T, U extends { any: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean;
/**
* Takes a list of predicates and returns a predicate that returns true for a
* given list of arguments if at least one of the provided predicates is
* satisfied by those arguments.
*
* The function returned is a curried function whose arity matches that of the
* highest-arity predicate.
*
* See also {@link allPass}, {@link either}
*
* @example
* ```typescript
* const isClub = R.propEq('♣', 'suit');
* const isSpade = R.propEq('♠', 'suit');
* const isBlackCard = R.anyPass([isClub, isSpade]);
*
* isBlackCard({rank: '10', suit: '♣'}); //=> true
* isBlackCard({rank: 'Q', suit: '♠'}); //=> true
* isBlackCard({rank: 'Q', suit: '♦'}); //=> false
* ```
*/
export function anyPass<T, TF1 extends T, TF2 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2],
): (a: T) => a is TF1 | TF2;
export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2, (a: T) => a is TF3],
): (a: T) => a is TF1 | TF2 | TF3;
export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2, (a: T) => a is TF3],
): (a: T) => a is TF1 | TF2 | TF3;
export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T>(
predicates: [(a: T) => a is TF1, (a: T) => a is TF2, (a: T) => a is TF3, (a: T) => a is TF4],
): (a: T) => a is TF1 | TF2 | TF3 | TF4;
export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T>(
predicates: [
(a: T) => a is TF1,
(a: T) => a is TF2,
(a: T) => a is TF3,
(a: T) => a is TF4,
(a: T) => a is TF5
],
): (a: T) => a is TF1 | TF2 | TF3 | TF4 | TF5;
export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T>(
predicates: [
(a: T) => a is TF1,
(a: T) => a is TF2,
(a: T) => a is TF3,
(a: T) => a is TF4,
(a: T) => a is TF5,
(a: T) => a is TF6
],
): (a: T) => a is TF1 | TF2 | TF3 | TF4 | TF5 | TF6;
export function anyPass<F extends (...args: any[]) => boolean>(predicates: readonly F[]): F;
/**
* ap applies a list of functions to a list of values.
*
* Dispatches to the `ap` method of the first argument, if present. Also
* treats curried functions as applicatives.
*
* @example
* ```typescript
* R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]
* R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"]
*
* // R.ap can also be used as S combinator
* // when only two functions are passed
* R.ap(R.concat, R.toUpper)('Ramda') //=> 'RamdaRAMDA'
* ```
*/
export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>): (vs: readonly T[]) => U[];
export function ap<R, A, B>(fn: (r: R, a: A) => B, fn1: (r: R) => A): (r: R) => B;
export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>, vs: readonly T[]): U[];
/**
* Returns a new list, composed of n-tuples of consecutive elements. If `n` is
* greater than the length of the list, an empty list is returned.
*
* Acts as a transducer if a transformer is given in list position.
*
* See also {@link transduce}
*
* @example
* ```typescript
* R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]]
* R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
* R.aperture(7, [1, 2, 3, 4, 5]); //=> []
* ```
*/
export function aperture<N extends number>(n: N): <T>(list: readonly T[]) => Array<Tuple<T, N>> | [];
export function aperture<T>(__: Placeholder, list: readonly T[]): <N extends number>(n: N) => Array<Tuple<T, N>> | [];
export function aperture<N extends number, T>(n: N, list: readonly T[]): Array<Tuple<T, N>> | [];
/**
* Returns a new list containing the contents of the given list, followed by
* the given element.
*
* See also {@link prepend}
*
* @example
* ```typescript
* R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
* R.append('tests', []); //=> ['tests']
* R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
* ```
*/
export function append<T>(el: T): (list: readonly T[]) => T[];
// append(__, list)(el)
export function append<T>(__: Placeholder, list: readonly T[]): (el: T) => T[];
// append(el, list)
export function append<T>(el: T, list: readonly T[]): T[];
/**
* Applies function `fn` to the argument list `args`. This is useful for
* creating a fixed-arity function from a variadic function. `fn` should be a
* bound function if context is significant.
*
* See also {@link call}, {@link unapply}
*
* @example
* ```typescript
* const nums = [1, 2, 3, -99, 42, 6, 7];
* R.apply(Math.max, nums); //=> 42
* ```
*/
export function apply<F extends (...args: readonly any[]) => any>(fn: F): (args: Parameters<F>) => ReturnType<F>;
// apply(args, fn)
// overload Placeholder options with versions for 1-to-5 args for best constraining
export function apply<A extends readonly [any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
export function apply<A extends readonly [any, any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
export function apply<A extends readonly [any, any, any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
export function apply<A extends readonly [any, any, any, any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
export function apply<A extends readonly [any, any, any, any, any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
export function apply<A extends readonly any[]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
// apply(args, fn)
export function apply<F extends (...args: readonly any[]) => any>(fn: F, args: Parameters<F>): ReturnType<F>;
/**
* Given a spec object recursively mapping properties to functions, creates a
* function producing an object of the same structure, by mapping each property
* to the result of calling its associated function with the supplied arguments.
*
* See also {@link converge}, {@link juxt}
*
* @example
* ```typescript
* const getMetrics = R.applySpec({
* sum: R.add,
* nested: { mul: R.multiply }
* });
* getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } }
* ```
*/
export function applySpec<Obj extends Record<string, (...args: readonly any[]) => any>>(
obj: Obj,
): (...args: Parameters<Obj[keyof Obj]>) => { [Key in keyof Obj]: ReturnType<Obj[Key]> };
export function applySpec<T>(obj: any): (...args: readonly any[]) => T;
/**
* Takes a value and applies a function to it.
*
* This function is also known as the `thrush` combinator.
*
* @example
* ```typescript
* const t42 = R.applyTo(42);
* t42(R.identity); //=> 42
* t42(R.add(1)); //=> 43
* ```
*/
export function applyTo<T>(el: T): <U>(fn: (t: T) => U) => U;
export function applyTo<T, U>(el: T, fn: (t: T) => U): U;
/**
* Makes an ascending comparator function out of a function that returns a value
* that can be compared with `<` and `>`.
*
* See also {@link descend}, {@link ascendNatural}, {@link descendNatural}
*
* @example
* ```typescript
* const byAge = R.ascend(R.prop('age'));
* const people = [
* { name: 'Emma', age: 70 },
* { name: 'Peter', age: 78 },
* { name: 'Mikhail', age: 62 },
* ];
* const peopleByYoungestFirst = R.sort(byAge, people);
* //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
* ```
*/
export function ascend<T>(fn: (obj: T) => Ord): (a: T, b: T) => Ordering;
export function ascend<T>(fn: (obj: T) => Ord, a: T, b: T): Ordering;
/**
* Makes an ascending comparator function out of a function that returns a value
* that can be compared with natural sorting using localeCompare.
*
* See also {@link ascend}
*
* @example
* ```typescript
* const unsorted = ['3', '1', '10', 'Ørjan', 'Bob', 'Älva'];
*
* R.sort(R.ascendNatural('en', R.identity), unsorted);
* // => ['1', '3', '10', 'Älva', 'Bob', 'Ørjan']
*
* R.sort(R.ascendNatural('sv', R.identity), unsorted);
* // => ['1', '3', '10', 'Bob', 'Älva', 'Ørjan']
*
* R.sort(R.ascend(R.identity), unsorted);
* // => ['1', '10', '3', 'Bob', 'Älva', 'Ørjan']
* ```
*/
export function ascendNatural(locales: string | string[]): <T>(fn: (obj: T) => string) => (a: T, b: T) => Ordering;
export function ascendNatural<T>(locales: string | string[], fn: (obj: T) => string): (a: T, b: T) => Ordering;
export function ascendNatural<T>(locales: string | string[], fn: (obj: T) => string, a: T, b: T): Ordering;
/**
* Makes a shallow clone of an object, setting or overriding the specified
* property with the given value. Note that this copies and flattens prototype
* properties onto the new object as well. All non-primitive properties are
* copied by reference.
*
* See also {@link dissoc}, {@link pick}
*
* @example
* ```typescript
* R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
*
* R.assoc(4, 3, [1, 2]); //=> [1, 2, undefined, undefined, 3]
* R.assoc(-1, 3, [1, 2]); //=> [1, 3]
* ```
*/
export function assoc<K extends PropertyKey>(prop: K): {
// assoc(prop)(val)(obj)
<T>(val: T): {
<U>(obj: U): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
}
// assoc(prop)(__, obj)(val)
<U>(__: Placeholder, obj: U): {
<T>(val: T): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
}
// assoc(prop)(val, obj)
<T, U>(val: T, obj: U): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
};
// assoc(__, val)
export function assoc<T>(__: Placeholder, val: T) : {
// assoc(__, val)(prop)(obj)
<K extends PropertyKey>(prop: K): {
<U>(obj: U): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
}
// assoc(__, val)(__, obj)(prop)
<U>(__2: Placeholder, obj: U): {
<K extends PropertyKey>(prop: K): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
};
// assoc(__, val)(prop, obj)
<K extends PropertyKey, U>(prop: K, obj: U): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
};
// assoc(prop, val)(obj)
export function assoc<T, K extends PropertyKey>(prop: K, val: T): {
<U>(obj: U): U extends Record<K, any> ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
};
// assoc(__, __, obj)
export function assoc<U>(__: Placeholder, __2: Placeholder, obj: U): {
// assoc(__, __, obj)(key)(val)
<K extends PropertyKey>(key: K): {
<T>(val: T): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
}
// assoc(__, __, obj)(__, value)(key)
<T>(__: Placeholder, val: T): {
<K extends PropertyKey>(key: K): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
}
// assoc(__, __, obj)(key, value)
<K extends PropertyKey, T>(key: K, val: T): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
};
// assoc(__, val, obj)(prop)
export function assoc<T, U>(__: Placeholder, val: T, obj: U): <K extends PropertyKey>(prop: K) => K extends keyof U ? T extends U[K] ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
// assoc(prop, __, obj)(val)
export function assoc<U, K extends PropertyKey>(prop: K, __: Placeholder, obj: U): <T>(val: T) => K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
// assoc(prop, val, obj)
export function assoc<T, U, K extends PropertyKey>(prop: K, val: T, obj: U): K extends keyof U ? U[K] extends T ? U : Record<K, T> & Omit<U, K> : U & Record<K, T>;
/**
* Makes a shallow clone of an object, setting or overriding the nodes required
* to create the given path, and placing the specific value at the tail end of
* that path. Note that this copies and flattens prototype properties onto the
* new object as well. All non-primitive properties are copied by reference.
*
* See also {@link dissocPath}
*
* @example
* ```typescript
* R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
*
* // Any missing or non-object keys in path will be overridden
* R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}}
* R.assocPath(['a', 1, 'c'], 42, {a: []}); // => {a: [undefined, {c: 42}]}
* R.assocPath(['a', -1], 42, {a: [1, 2]}); // => {a: [1, 42]}
* ```
*/
export function assocPath<T, U>(path: Path): _.F.Curry<(a: T, b: U) => U>;
export function assocPath<T, U>(path: Path, val: T): (obj: U) => U;
export function assocPath<T, U>(__: Placeholder, val: T, obj: U): (path: Path) => U;
export function assocPath<T, U>(path: Path, __: Placeholder, obj: U): (val: T) => U;
export function assocPath<T, U>(path: Path, val: T, obj: U): U;
/**
* Wraps a function of any arity (including nullary) in a function that accepts
* exactly 2 parameters. Any extraneous parameters will not be passed to the
* supplied function.
*
* See also {@link nAry}, {@link unary}
*
* @example
* ```typescript
* const takesThreeArgs = function(a, b, c) {
* 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]
* ```
*/
export function binary<T extends (...arg: any) => any>(fn: T): (...arg: _.T.Take<Parameters<T>, 2>) => ReturnType<T>;
/**
* Creates a function that is bound to a context.
* Note: `R.bind` does not provide the additional argument-binding capabilities of
* [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
*
* See also {@link partial}
*
* @example
* ```typescript
* const log = R.bind(console.log, console);
* R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3}
* // logs {a: 2}
* ```
*/
export function bind<F extends (...args: readonly any[]) => any, T>(
fn: F,
): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>;
export function bind<F extends (...args: readonly any[]) => any, T>(
fn: F,
thisObj: T,
): (...args: Parameters<F>) => ReturnType<F>;
/**
* A function which calls the two provided functions and returns the `&&`
* of the results.
* It returns the result of the first function if it is false-y and the result
* of the second function otherwise. Note that this is short-circuited,
* meaning that the second function will not be invoked if the first returns a
* false-y value.
*
* In addition to functions, `R.both` also accepts any fantasy-land compatible
* applicative functor.
*
* See also {@link either}, {@link allPass}, {@link and}
*
* @example
* ```typescript
* const gt10 = R.gt(R.__, 10)
* const lt20 = R.lt(R.__, 20)
* const f = R.both(gt10, lt20);
* f(15); //=> true
* f(30); //=> false
*
* R.both(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(false)
* R.both([false, false, 'a'], [11]); //=> [false, false, 11]
* ```
*/
export function both<T, RT1 extends T>(f: (a: T) => a is RT1): <RT2 extends T>(g: (a: T) => a is RT2) => (a: T) => a is RT1 & RT2;
export function both<Args extends any[]>(f: (...args: Args) => boolean): (g: (...args: Args) => boolean) => (...args: Args) => boolean;
// both(f, g) => (x: T) => boolean
export function both<T, RT1 extends T, RT2 extends T>(f: (a: T) => a is RT1, g: (a: T) => a is RT2): (a: T) => a is RT1 & RT2;
export function both<Args extends any[]>(f: (...args: Args) => boolean, g: (...args: Args) => boolean): (...args: Args) => boolean;
/**
* Returns the result of calling its first argument with the remaining
* arguments. This is occasionally useful as a converging function for
* [`R.converge`](#converge): the first branch can produce a function while the
* remaining branches produce values to be passed to that function as its
* arguments.
*
* See also {@link apply}
*
* @example
* ```typescript
* R.call(R.add, 1, 2); //=> 3
*
* const indentN = R.pipe(
* R.repeat(' '),
* R.join(''),
* R.replace(/^(?!$)/gm)
* );
*
* const format = R.converge(
* R.call,
* [
* R.pipe(R.prop('indent'), indentN),
* R.prop('value')
* ]
* );
*
* format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n'
* ```
*/
export function call<T extends (...args: readonly any[]) => any>(fn: T, ...args: Parameters<T>): ReturnType<T>;
/**
* `chain` maps a function over a list and concatenates the results. `chain`
* is also known as `flatMap` in some libraries.
*
* Dispatches to the `chain` method of the second argument, if present,
* according to the [FantasyLand Chain spec](https://github.com/fantasyland/fantasy-land#chain).
*
* If second argument is a function, `chain(f, g)(x)` is equivalent to `f(g(x), x)`.
*
* Acts as a transducer if a transformer is given in list position.
*
* @example
* ```typescript
* const duplicate = n => [n, n];
* R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]
*
* R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1]
* ```
*/
export function chain<A, B>(fn: (n: A) => readonly B[], list: readonly A[]): B[];
// chain(fn)(list)
export function chain<A, B>(fn: (n: A) => readonly B[]): (list: readonly A[]) => B[];
// chain(fn, monad)
export function chain<A, Ma extends { chain: (fn: (a: A) => Mb) => Mb }, Mb>(fn: (a: A) => Mb, monad: Ma): Mb;
// chain(fn)(monad)
export function chain<A, Ma extends { chain: (fn: (a: A) => Mb) => Mb }, Mb>(fn: (a: A) => Mb): (monad: Ma) => Mb;
// chain (f, g)(x)
export function chain<A, B, R>(aToMb: (a: A, r: R) => B, Ma: (r: R) => A): (r: R) => B;
// chain (f)(g)(x)
export function chain<A, B, R>(aToMb: (a: A, r: R) => B): (Ma: (r: R) => A) => (r: R) => B;
// TODO: types for transducer variation
/**
* Restricts a number to be within a range.
*
* Also works for other ordered types such as Strings and Dates.
*
* @example
* ```typescript
* R.clamp(1, 10, -5) // => 1
* R.clamp(1, 10, 15) // => 10
* R.clamp(1, 10, 4) // => 4
* ```
*/
export function clamp<T>(min: T): {
(max: T): (value: T) => T;
(max: T, value: T): T
};
export function clamp<T>(min: T, max: T): (value: T) => T;
export function clamp<T>(min: T, max: T, value: T): T;
/**
* Creates a deep copy of the source that can be used in place of the source
* object without retaining any references to it.
* The source object may contain (nested) `Array`s and `Object`s,
* `Number`s, `String`s, `Boolean`s and `Date`s.
* `Function`s are assigned by reference rather than copied.
*
* Dispatches to a `clone` method if present.
*
* Note that if the source object has multiple nodes that share a reference,
* the returned object will have the same structure, but the references will
* be pointed to the location within the cloned value.
*
* @example
* ```typescript
* const objects = [{}, {}, {}];
* const objectsClone = R.clone(objects);
* objects === objectsClone; //=> false
* objects[0] === objectsClone[0]; //=> false
* ```
*/
export function clone<T>(value: readonly T[]): T[];
export function clone<T>(value: T): T;
/**
* Splits a list into sub-lists, based on the result of calling a key-returning function on each element,
* and grouping the results according to values returned.
*
* See also {@link groupBy}, {@link partition}
*
* @example
* ```typescript
* R.collectBy(R.prop('type'), [
* {type: 'breakfast', item: '☕️'},
* {type: 'lunch', item: '🌯'},
* {type: 'dinner', item: '🍝'},
* {type: 'breakfast', item: '🥐'},
* {type: 'lunch', item: '🍕'}
* ]);
*
* // [ [ {type: 'breakfast', item: '☕️'},
* // {type: 'breakfast', item: '🥐'} ],
* // [ {type: 'lunch', item: '🌯'},
* // {type: 'lunch', item: '🍕'} ],
* // [ {type: 'dinner', item: '🍝'} ] ]
* ```
*/
export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K): (list: readonly T[]) => T[][];
export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: readonly T[]): T[][];
/**
* Makes a comparator function out of a function that reports whether the first
* element is less than the second.
*
* @example
* ```typescript
* const byAge = R.comparator((a, b) => a.age < b.age);
* const people = [
* { name: 'Emma', age: 70 },
* { name: 'Peter', age: 78 },
* { name: 'Mikhail', age: 62 },
* ];
* const peopleByIncreasingAge = R.sort(byAge, people);
* //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
* ```
*/
export function comparator<T>(pred: (a: T, b: T) => boolean): (x: T, y: T) => Ordering;
/**
* Takes a function `f` and returns a function `g` such that if called with the same arguments
* when `f` returns a "truthy" value, `g` returns `false` and when `f` returns a "falsy" value `g` returns `true`.
*
* `R.complement` may be applied to any functor
*
* See also {@link not}
*
* @example
* ```typescript
* const isNotNil = R.complement(R.isNil);
* R.isNil(null); //=> true
* isNotNil(null); //=> false
* R.isNil(7); //=> false
* isNotNil(7); //=> true
* ```
*/
export function complement<T, TFiltered extends T>(
pred: (value: T) => value is TFiltered,
): (value: T) => value is Exclude<T, TFiltered>;
export function complement<TArgs extends any[]>(pred: (...args: TArgs) => unknown): (...args: TArgs) => boolean;
/**
* Performs right-to-left function composition. The last argument may have
* any arity; the remaining arguments must be unary.
*
* **Note:** The result of compose is not automatically curried.
*
* See also {@link pipe}
*
* @example
* ```typescript
* const classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName
* const yellGreeting = R.compose(R.toUpper, classyGreeting);
* yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND"
*
* R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7
* ```
*/
export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
...func: [
fnLast: (a: any) => TResult,
...func: Array<(a: any) => any>,
f7: (a: R6) => R7,
f6: (a: R5) => R6,
f5: (a: R4) => R5,
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1
]
): (...args: TArgs) => TResult;
// fallback overload if number of composed functions greater than 7
export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
f7: (a: R6) => R7,
f6: (a: R5) => R6,
f5: (a: R4) => R5,
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R7;
export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
f7: (a: R6) => R7,
f6: (a: R5) => R6,
f5: (a: R4) => R5,
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R7;
export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
f6: (a: R5) => R6,
f5: (a: R4) => R5,
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R6;
export function compose<TArgs extends any[], R1, R2, R3, R4, R5>(
f5: (a: R4) => R5,
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R5;
export function compose<TArgs extends any[], R1, R2, R3, R4>(
f4: (a: R3) => R4,
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R4;
export function compose<TArgs extends any[], R1, R2, R3>(
f3: (a: R2) => R3,
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R3;
export function compose<TArgs extends any[], R1, R2>(
f2: (a: R1) => R2,
f1: (...args: TArgs) => R1,
): (...args: TArgs) => R2;
export function compose<TArgs extends any[], R1>(f1: (...args: TArgs) => R1): (...args: TArgs) => R1;
/**
* Performs right-to-left function composition using transforming function. The last function may have
* any arity; the remaining functions must be unary. Unlike `compose`, functions are passed in an array.
*
* **Note:** The result of composeWith is not automatically curried. Transforming function is not used
* on the last argument.
*
* See also {@link compose}, {@link pipeWith}
*
* @example
* ```typescript
* const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
*
* composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
* composeWhileNotNil([R.inc, R.prop('age')])({}) //=> undefined
* ```
*/
export function composeWith(
transformer: (fn: (...args: any[]) => any, intermediatResult: any) => any,
): <TArgs extends any[], TResult>(
fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
) => (...args: TArgs) => TResult;
export function composeWith<TArgs extends any[], TResult>(
transformer: (fn: (...args: any[]) => any, intermediatResult: any) => any,
fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
): (...args: TArgs) => TResult;
/**
* Returns the result of concatenating the given lists or strings.
*
* Note: `R.concat` expects both arguments to be of the same type,
* unlike the native `Array.prototype.concat` method. It will throw
* an error if you `concat` an Array with a non-Array value.
*
* Dispatches to the `concat` method of the first argument, if present.
* Can also concatenate two members of a [fantasy-land
* compatible semigroup](https://github.com/fantasyland/fantasy-land#semigroup).
*
* @example
* ```typescript
* R.concat('ABC', 'DEF'); // 'ABCDEF'
* R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
* R.concat([], []); //=> []
* ```
*/
export function concat<S1 extends string>(s1: S1): <S2 extends string>(s2: S2) => string extends (S1 | S2) ? string : `${S1}${S2}`;
// concat(list)(list)
export function concat<T>(list1: readonly T[]): (list2: readonly T[]) => T[];
// concat(__, string)(string)
export function concat<S2 extends string>(__: Placeholder, s2: S2): <S1 extends string>(s1: S1) => string extends (S1 | S2) ? string : `${S1}${S2}`;
// concat(__, list)(list)
export function concat<T2>(__: Placeholder, list2: readonly T2[]): <T1>(list1: (readonly T2[] extends readonly T1[] ? readonly T1[] : never)) => T1[];
// concat(string, string)
export function concat<S1 extends string, S2 extends string>(s1: S1, s2: S2): string extends (S1 | S2) ? string : `${S1}${S2}`;
// concat(list, list)
// if you don't do 2 types here the single T will collapse list1 and list2 when you have tuples of the same type, which is incorrect behavior
export function concat<T1, T2 extends T1>(list1: readonly T1[], list2: readonly T2[]): T1[];
/**
* Returns a function, `fn`, which encapsulates `if/else, if/else, ...` logic.
* `R.cond` takes a list of [predicate, transformer] pairs. All of the arguments
* to `fn` are applied to each of the predicates in turn until one returns a
* "truthy" value, at which point `fn` returns the result of applying its
* arguments to the corresponding transformer. If none of the predicates
* matches, `fn` returns undefined.
*
* **Please note**: This is not a direct substitute for a `switch` statement.
* Remember that both elements of every pair passed to `cond` are *functions*,
* and `cond` returns a function.
*
* See also {@link ifElse}, {@link unless}, {@link when}
*
* @example
* ```typescript
* const fn = R.cond([
* [R.equals(0), R.always('water freezes at 0°C')],
* [R.equals(100), R.always('water boils at 100°C')],
* [R.T, temp => 'nothing special happens at ' + temp + '°C']
* ]);
* fn(0); //=> 'water freezes at 0°C'
* fn(50); //=> 'nothing special happens at 50°C'
* fn(100); //=> 'water boils at 100°C'
* ```
*/
export function cond<T, TF1 extends T, R>(pairs: [CondPairTypeguard<T, TF1, R>]): (value: T) => R;
export function cond<T, TF1 extends T, TF2 extends T, R>(
pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>],
): (value: T) => R;
export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, R>(
pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>, CondPairTypeguard<T, TF3, R>],
): (value: T) => R;
export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, R>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>
],
): (value: T) => R;
export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, R>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>
],
): (value: T) => R;
export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T, R>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>,
CondPairTypeguard<T, TF6, R>
],
): (value: T) => R;
export function cond<
T,
TF1 extends T,
TF2 extends T,
TF3 extends T,
TF4 extends T,
TF5 extends T,
TF6 extends T,
TF7 extends T,
R
>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>,
CondPairTypeguard<T, TF6, R>,
CondPairTypeguard<T, TF7, R>
],
): (value: T) => R;
export function cond<
T,
TF1 extends T,
TF2 extends T,
TF3 extends T,
TF4 extends T,
TF5 extends T,
TF6 extends T,
TF7 extends T,
TF8 extends T,
R
>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>,
CondPairTypeguard<T, TF6, R>,
CondPairTypeguard<T, TF7, R>,
CondPairTypeguard<T, TF8, R>
],
): (value: T) => R;
export function cond<
T,
TF1 extends T,
TF2 extends T,
TF3 extends T,
TF4 extends T,
TF5 extends T,
TF6 extends T,
TF7 extends T,
TF8 extends T,
TF9 extends T,
R
>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>,
CondPairTypeguard<T, TF6, R>,
CondPairTypeguard<T, TF7, R>,
CondPairTypeguard<T, TF8, R>,
CondPairTypeguard<T, TF9, R>
],
): (value: T) => R;
export function cond<
T,
TF1 extends T,
TF2 extends T,
TF3 extends T,
TF4 extends T,
TF5 extends T,
TF6 extends T,
TF7 extends T,
TF8 extends T,
TF9 extends T,
TF10 extends T,
R
>(
pairs: [
CondPairTypeguard<T, TF1, R>,
CondPairTypeguard<T, TF2, R>,
CondPairTypeguard<T, TF3, R>,
CondPairTypeguard<T, TF4, R>,
CondPairTypeguard<T, TF5, R>,
CondPairTypeguard<T, TF6, R>,
CondPairTypeguard<T, TF7, R>,
CondPairTypeguard<T, TF8, R>,
CondPairTypeguard<T, TF9, R>,
CondPairTypeguard<T, TF10, R>
],
): (value: T) => R;
export function cond<T extends any[], R>(pairs: Array<CondPair<T, R>>): (...args: T) => R;
/**
* Wraps a constructor function inside a curried function that can be called
* with the same arguments and returns the same type.
*
* See also {@link invoker}
*
* @example
* ```typescript
* // Constructor function
* function Animal(kind) {
* this.kind = kind;
* };
* Animal.prototype.sighting = function() {
* return "It's a " + this.kind + "!";
* }
*
* const AnimalConstructor = R.construct(Animal)
*
* // Notice we no longer need the 'new' keyword:
* AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}};
*
* const animalTypes = ["Lion", "Tiger", "Bear"];
* const animalSighting = R.invoker(0, 'sighting');
* const sightNewAnimal = R.compose(animalSighting, AnimalConstructor);
* R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"]
* ```
*/
export function construct<A extends any[], T>(
constructor: { new (...a: A): T } | ((...a: A) => T),
): _.F.Curry<(...a: A) => T>;
/**
* Wraps a constructor function inside a curried function that can be called
* with the same arguments and returns the same type. The arity of the function
* returned is specified to allow using variadic constructor functions.
*
* @example
* ```typescript
* // Variadic Constructor function
* function Salad() {
* this.ingredients = arguments;
* }
*
* Salad.prototype.recipe = function() {
* const instructions = R.map(ingredient => 'Add a dollop of ' + ingredient, this.ingredients);
* return R.join('\n', instructions);
* };
*
* const ThreeLayerSalad = R.constructN(3, Salad);
*
* // Notice we no longer need the 'new' keyword, and the constructor is curried for 3 arguments.
* const salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup');
*
* console.log(salad.recipe());
* // Add a dollop of Mayonnaise
* // Add a dollop of Potato Chips
* // Add a dollop of Ketchup
* ```
*/
export function constructN<A extends any[], T, N extends number>(
n: N,
constructor: { new (...a: A): T } | ((...a: A) => T),
): _.F.Curry<(...a: mergeArrWithLeft<Tuple<any, N>, A>) => T>;
/**
* Accepts a converging function and a list of branching functions and returns
* a new function. The arity of the new function is the same as the arity of
* the longest branching function. When invoked, this new function is applied
* to some arguments, and each branching function is applied to those same
* arguments. The results of each branching function are passed as arguments
* to the converging function to produce the return value.
*
* See also {@link useWith}
*
* @example
* ```typescript
* const average = R.converge(R.divide, [R.sum, R.length])
* average([1, 2, 3, 4, 5, 6, 7]) //=> 4
*
* const strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower])
* strangeConcat("Yodel") //=> "YODELyodel"
* ```
*/
export function converge<
TResult,
FunctionsList extends ReadonlyArray<Fn> &
IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
_Fns extends ReadonlyArray<Fn> = FunctionsList
>(
converging: (...args: ReturnTypesOfFns<FunctionsList>) => TResult,
branches: FunctionsList,
): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
export function converge<
CArgs extends ReadonlyArray<any>,
TResult,
FunctionsList extends readonly [
...{
[Index in keyof CArgs]: (...args: ReadonlyArray<any>) => CArgs[Index];
}
] &
IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
_Fns extends ReadonlyArray<Fn> = FunctionsList
>(
converging: (...args: CArgs) => TResult,
branches: FunctionsList,
): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
/**
* Returns the number of items in a given `list` matching the predicate `f`
*
* @example
* ```typescript
* const even = x => x % 2 == 0;
*
* R.count(even, [1, 2, 3, 4, 5]); // => 2
* R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
* ```
*/
export function count<T>(fn: (a: T) => boolean): (list: readonly T[]) => number;
export function count<T>(fn: (a: T) => boolean, list: readonly T[]): number;
/**
* Counts the elements of a list according to how many match each value of a
* key generated by the supplied function. Returns an object mapping the keys
* produced by `fn` to the number of occurrences in the list. Note that all
* keys are coerced to strings because of how JavaScript objects work.
*
* Acts as a transducer if a transformer is given in list position.
*
* @example
* ```typescript
* const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
* R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
*
* const letters = ['a', 'b', 'A', 'a', 'B', 'c'];
* R.countBy(R.toLower)(letters); //=> {'a': 3