UNPKG

212 kBTypeScriptView Raw
1// Type definitions for ramda 0.28
2// Project: https://ramdajs.com
3// Definitions by: Scott O'Malley <https://github.com/TheHandsomeCoder>
4// Erwin Poeze <https://github.com/donnut>
5// Matt DeKrey <https://github.com/mdekrey>
6// Stephen King <https://github.com/sbking>
7// Alejandro Fernandez Haro <https://github.com/afharo>
8// Vítor Castro <https://github.com/teves-castro>
9// Simon Højberg <https://github.com/hojberg>
10// Samson Keung <https://github.com/samsonkeung>
11// Angelo Ocana <https://github.com/angeloocana>
12// Rayner Pupo <https://github.com/raynerd>
13// Nikita Moshensky <https://github.com/moshensky>
14// Ethan Resnick <https://github.com/ethanresnick>
15// Tomas Szabo <https://github.com/deftomat>
16// Maciek Blim <https://github.com/blimusiek>
17// Marcin Biernat <https://github.com/biern>
18// Rayhaneh Banyassady <https://github.com/rayhaneh>
19// Ryan McCuaig <https://github.com/rgm>
20// Drew Wyatt <https://github.com/drewwyatt>
21// John Ottenlips <https://github.com/jottenlips>
22// Nitesh Phadatare <https://github.com/minitesh>
23// Krantisinh Deshmukh <https://github.com/krantisinh>
24// Aram Kharazyan <https://github.com/nemo108>
25// Jituan Lin <https://github.com/jituanlin>
26// Philippe Mills <https://github.com/Philippe-mills>
27// Saul Mirone <https://github.com/Saul-Mirone>
28// Nicholai Nissen <https://github.com/Nicholaiii>
29// Jorge Santana <https://github.com/LORDBABUINO>
30// Mikael Couzic <https://github.com/couzic>
31// Nikita Balikhin <https://github.com/NEWESTERS>
32// Wang Zengdi <https://github.com/adispring>
33// Marcus Blättermann <https://github.com/essenmitsosse>
34// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
35// TypeScript Version: 4.2
36
37import * as _ from 'ts-toolbelt';
38import {
39 AnyConstructor,
40 AnyFunction,
41 AtLeastOneFunctionsFlow,
42 AtLeastOneFunctionsFlowFromRightToLeft,
43 AssocPartialOne,
44 CondPair,
45 CondPairTypeguard,
46 Dictionary,
47 Evolvable,
48 Evolve,
49 Evolver,
50 Falsy,
51 Find,
52 Functor,
53 InputTypesOfFns,
54 KeyValuePair,
55 Lens,
56 Merge,
57 MergeAll,
58 ObjectHavingSome,
59 ObjPred,
60 Ord,
61 Ordering,
62 Path,
63 Placeholder,
64 Pred,
65 PredTypeguard,
66 Reduced,
67 ReturnTypesOfFns,
68 ValueOfUnion,
69 Take,
70 ToTupleOfArray,
71 ToTupleOfFunction,
72 Tuple,
73 Fn,
74 IfFunctionsArgumentsDoNotOverlap,
75 LargestArgumentsList,
76 mergeArrWithLeft,
77} from './tools';
78
79export * from './tools';
80
81// NOTE: Example doesn't work with current level of support
82/**
83 * A special placeholder value used to specify "gaps" within curried functions,
84 * allowing partial application of any combination of arguments, regardless of their positions.
85 *
86 * If `g` is a curried ternary function and `_` is `R.__`, the following are equivalent:
87 * - `g(1, 2, 3)`
88 * - `g(_, 2, 3)(1)`
89 * - `g(_, _, 3)(1)(2)`
90 * - `g(_, _, 3)(1, 2)`
91 * - `g(_, 2, _)(1, 3)`
92 * - `g(_, 2)(1)(3)`
93 * - `g(_, 2)(1, 3)`
94 * - `g(_, 2)(_, 3)(1)`
95 *
96 * @example
97 * ```typescript
98 * const greet = R.replace('{name}', R.__, 'Hello, {name}!');
99 * greet('Alice'); //=> 'Hello, Alice!'
100 * ```
101 */
102export const __: Placeholder;
103
104/**
105 * Adds two values. Equivalent to `a + b` but curried.
106 *
107 * @example
108 * ```typescript
109 * R.add(2, 3); //=> 5
110 * R.add(7)(10); //=> 17
111 * ```
112 */
113export function add(a: number, b: number): number;
114export function add(a: number): (b: number) => number;
115
116/**
117 * Creates a new list iteration function from an existing one by adding two new parameters to its callback
118 * function: the current index, and the entire list.
119 *
120 * This would turn, for instance, {@link map `R.map`} function into one that more closely resembles `Array.prototype.map`.
121 *
122 * @note This will only work for functions in which the iteration callback function is the first parameter,
123 * and where the list is the last parameter.
124 * (This latter might be unimportant if the list parameter is not used.)
125 *
126 * See also {@link subtract}.
127 *
128 * @example
129 * ```typescript
130 * const mapIndexed = R.addIndex(R.map);
131 * mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
132 * //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
133 * ```
134 */
135/* Special case for forEach */
136export function addIndex<T>(
137 fn: (f: (item: T) => void, list: readonly T[]) => T[],
138): _.F.Curry<(a: (item: T, idx: number, list: T[]) => void, b: readonly T[]) => T[]>;
139/* Special case for filter */
140export function addIndex<T>(
141 fn: (f: (item: T) => boolean, list: readonly T[]) => T[],
142): _.F.Curry<(a: (item: T, idx: number, list: T[]) => boolean, b: readonly T[]) => T[]>;
143/* Special case for map */
144export function addIndex<T, U>(
145 fn: (f: (item: T) => U, list: readonly T[]) => U[],
146): _.F.Curry<(a: (item: T, idx: number, list: T[]) => U, b: readonly T[]) => U[]>;
147/* Special case for reduce */
148export function addIndex<T, U>(
149 fn: (f: (acc: U, item: T) => U, aci: U, list: readonly T[]) => U,
150): _.F.Curry<(a: (acc: U, item: T, idx: number, list: T[]) => U, b: U, c: readonly T[]) => U>;
151
152/**
153 * Applies a function to the value at the given index of an array, returning a new copy of the array with the
154 * element at the given index replaced with the result of the function application.
155 *
156 * See also {@link update}.
157 *
158 * @example
159 * ```typescript
160 * R.adjust(1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'B', 'c', 'd']
161 * R.adjust(-1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'D']
162 * ```
163 */
164export function adjust<T>(index: number, fn: (a: T) => T, list: readonly T[]): T[];
165export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
166
167/**
168 * Returns `true` if all elements of the list match the predicate, `false` if there are any that don't.
169 *
170 * Dispatches to the `all` method of the second argument, if present.
171 *
172 * Acts as a transducer if a transformer is given in list position.
173 *
174 * See also {@link any}, {@link none}, {@link transduce}.
175 *
176 * @example
177 * ```typescript
178 * const equals3 = R.equals(3);
179 * R.all(equals3)([3, 3, 3, 3]); //=> true
180 * R.all(equals3)([3, 3, 1, 3]); //=> false
181 * ```
182 */
183export function all<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
184export function all<T>(fn: (a: T) => boolean): (list: readonly T[]) => boolean;
185
186/**
187 * Takes a list of predicates and returns a predicate that returns true for a given list of arguments
188 * if every one of the provided predicates is satisfied by those arguments.
189 *
190 * The function returned is a curried function whose arity matches that of the highest-arity predicate.
191 *
192 * See also {@link anyPass}.
193 *
194 * @example
195 * ```typescript
196 * type Card = { rank: string; suit: string; };
197 *
198 * const isQueen = R.propEq('rank', 'Q');
199 * const isSpade = R.propEq('suit', '♠︎');
200 * const isQueenOfSpades = R.allPass<R.Pred<[Card]>>([isQueen, isSpade]);
201 *
202 * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
203 * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true
204 * ```
205 */
206export function allPass<T, TF1 extends T, TF2 extends T>(
207 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>],
208): (a: T) => a is TF1 & TF2;
209export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
210 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>],
211): (a: T) => a is TF1 & TF2 & TF3;
212export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
213 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>],
214): (a: T) => a is TF1 & TF2 & TF3;
215export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T>(
216 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>, PredTypeguard<T, TF4>],
217): (a: T) => a is TF1 & TF2 & TF3 & TF4;
218export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T>(
219 preds: [
220 PredTypeguard<T, TF1>,
221 PredTypeguard<T, TF2>,
222 PredTypeguard<T, TF3>,
223 PredTypeguard<T, TF4>,
224 PredTypeguard<T, TF5>,
225 ],
226): PredTypeguard<T, TF1 & TF2 & TF3 & TF4 & TF5>;
227export function allPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T>(
228 preds: [
229 PredTypeguard<T, TF1>,
230 PredTypeguard<T, TF2>,
231 PredTypeguard<T, TF3>,
232 PredTypeguard<T, TF4>,
233 PredTypeguard<T, TF5>,
234 PredTypeguard<T, TF6>,
235 ],
236): PredTypeguard<T, TF1 & TF2 & TF3 & TF4 & TF5 & TF6>;
237export function allPass<F extends Pred>(preds: readonly F[]): F;
238
239/**
240 * Returns a function that always returns the given value.
241 *
242 * @note For non-primitives the value returned is a reference to the original value.
243 *
244 * This function is known as `const`, `constant`, or `K` (for K combinator) in other languages and libraries.
245 *
246 * @example
247 * ```typescript
248 * const t = R.always('Tee');
249 * t(); //=> 'Tee'
250 * ```
251 */
252export function always<T>(val: T): (...args: unknown[]) => T;
253
254/**
255 * A function that returns the first argument if it's falsy otherwise the second argument.
256 *
257 * See also {@link both}, {@link or}, {@link xor}.
258 *
259 * @note This is **not** short-circuited, meaning that if expressions are passed they are both evaluated.
260 *
261 * @example
262 * ```typescript
263 * R.and(true, true); //=> true
264 * R.and(true, false); //=> false
265 * R.and(false, true); //=> false
266 * R.and(false, false); //=> false
267 * ```
268 */
269export function and<T, U>(a: T, b: U): T | U;
270export function and<T>(a: T): <U>(b: U) => T | U;
271
272/**
273 * Returns the result of applying the `onSuccess` function to the value inside a successfully resolved `Promise`.
274 * This is useful for working with `Promise`s inside function compositions.
275 *
276 * See also {@link otherwise}.
277 *
278 * @example
279 * ```typescript
280 * type Query = { query: { email: string; }; };
281 *
282 * const makeQuery = (email: string) => ({ query: { email }});
283 * const fetchMember = (request: Query) =>
284 * Promise.resolve({ firstName: 'Bob', lastName: 'Loblaw', id: 42 });
285 *
286 * //getMemberName :: String -> Promise ({ firstName, lastName })
287 * const getMemberName = R.pipe(
288 * makeQuery,
289 * fetchMember,
290 * R.andThen(R.pick(['firstName', 'lastName']))
291 * );
292 *
293 * getMemberName('bob@gmail.com').then(console.log);
294 * ```
295 */
296export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>, promise: Promise<A>): Promise<B>;
297export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>): (promise: Promise<A>) => Promise<B>;
298
299/**
300 * Returns `true` if at least one of elements of the list match the predicate, `false` otherwise.
301 *
302 * Dispatches to the `any` method of the second argument, if present.
303 *
304 * Acts as a transducer if a transformer is given in list position.
305 *
306 * See also {@link all}, {@link none}, {@link transduce}.
307 *
308 * @example
309 * ```typescript
310 * const lessThan0 = R.flip(R.lt)(0);
311 * const lessThan2 = R.flip(R.lt)(2);
312 * R.any(lessThan0)([1, 2]); //=> false
313 * R.any(lessThan2)([1, 2]); //=> true
314 * ```
315 */
316export function any<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
317export function any<T>(fn: (a: T) => boolean): (list: readonly T[]) => boolean;
318
319/**
320 * Takes a list of predicates and returns a predicate that returns true for a
321 * given list of arguments if at least one of the provided predicates is
322 * satisfied by those arguments.
323 *
324 * The function returned is a curried function whose arity matches that of the
325 * highest-arity predicate.
326 *
327 * See also {@link allPass}.
328 *
329 * @example
330 * ```typescript
331 * type Card = { rank: string; suit: string; };
332 *
333 * const isClub = R.propEq('suit', '♣');
334 * const isSpade = R.propEq('suit', '♠');
335 * const isBlackCard = R.anyPass<R.Pred<[Card]>>([isClub, isSpade]);
336 *
337 * isBlackCard({rank: '10', suit: '♣'}); //=> true
338 * isBlackCard({rank: 'Q', suit: '♠'}); //=> true
339 * isBlackCard({rank: 'Q', suit: '♦'}); //=> false
340 * ```
341 */
342export function anyPass<T, TF1 extends T, TF2 extends T>(
343 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>],
344): (a: T) => a is TF1 | TF2;
345export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
346 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>],
347): (a: T) => a is TF1 | TF2 | TF3;
348export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T>(
349 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>],
350): (a: T) => a is TF1 | TF2 | TF3;
351export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T>(
352 preds: [PredTypeguard<T, TF1>, PredTypeguard<T, TF2>, PredTypeguard<T, TF3>, PredTypeguard<T, TF4>],
353): (a: T) => a is TF1 | TF2 | TF3 | TF4;
354export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T>(
355 preds: [
356 PredTypeguard<T, TF1>,
357 PredTypeguard<T, TF2>,
358 PredTypeguard<T, TF3>,
359 PredTypeguard<T, TF4>,
360 PredTypeguard<T, TF5>,
361 ],
362): PredTypeguard<T, TF1 | TF2 | TF3 | TF4 | TF5>;
363export function anyPass<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T>(
364 preds: [
365 PredTypeguard<T, TF1>,
366 PredTypeguard<T, TF2>,
367 PredTypeguard<T, TF3>,
368 PredTypeguard<T, TF4>,
369 PredTypeguard<T, TF5>,
370 PredTypeguard<T, TF6>,
371 ],
372): PredTypeguard<T, TF1 | TF2 | TF3 | TF4 | TF5 | TF6>;
373export function anyPass<F extends Pred>(preds: readonly F[]): F;
374
375/**
376 * `ap` applies a list of functions to a list of values.
377 *
378 * Dispatches to the `ap` method of the first argument, if present.
379 * Also treats curried functions as applicatives.
380 *
381 * @example
382 * ```typescript
383 * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]
384 * R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"]
385 *
386 * // R.ap can also be used as S combinator
387 * // when only two functions are passed
388 * R.ap((s, s2) => R.concat(s, s2), R.toUpper)('Ramda') //=> 'RamdaRAMDA'
389 * ```
390 */
391export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>, vs: readonly T[]): U[];
392export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>): (vs: readonly T[]) => U[];
393export function ap<R, A, B>(fn: (r: R, a: A) => B, fn1: (r: R) => A): (r: R) => B;
394
395/**
396 * Returns a new list, composed of n-tuples of consecutive elements.
397 * If `n` is greater than the length of the list, an empty list is returned.
398 *
399 * Acts as a transducer if a transformer is given in list position.
400 *
401 * See also {@link transduce}.
402 *
403 * @example
404 * ```typescript
405 * R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]]
406 * R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
407 * R.aperture(7, [1, 2, 3, 4, 5]); //=> []
408 * ```
409 */
410export function aperture<N extends number, T>(n: N, list: readonly T[]): Array<Tuple<T, N>> | [];
411export function aperture<N extends number>(n: N): <T>(list: readonly T[]) => Array<Tuple<T, N>> | [];
412
413/**
414 * Returns a new list containing the contents of the given list, followed by the given element.
415 *
416 * See also {@link prepend}.
417 *
418 * @example
419 * ```typescript
420 * R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
421 * R.append('tests', []); //=> ['tests']
422 * R.append<string | string[]>(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
423 * ```
424 */
425export function append<T>(el: T, list: readonly T[]): T[];
426export function append<T>(el: T): (list: readonly T[]) => T[];
427
428/**
429 * Applies function `fn` to the argument list `args`.
430 * This is useful for creating a fixed-arity function from a variadic function.
431 * `fn` should be a bound function if context is significant.
432 *
433 * See also {@link call}, {@link unapply}.
434 */
435export function apply<F extends AnyFunction>(fn: F, args: Parameters<F>): ReturnType<F>;
436export function apply<F extends AnyFunction>(fn: F): (args: Parameters<F>) => ReturnType<F>;
437
438/**
439 * Given a spec object recursively mapping properties to functions,
440 * creates a function producing an object of the same structure,
441 * by mapping each property to the result of calling its associated function with the supplied arguments.
442 *
443 * See also {@link converge}, {@link juxt}.
444 *
445 * @example
446 * ```typescript
447 * const getMetrics = R.applySpec({
448 * sum: R.add,
449 * nested: { mul: R.multiply }
450 * });
451 * getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } }
452 * ```
453 */
454export function applySpec<Obj extends Record<string, AnyFunction>>(
455 obj: Obj,
456): (...args: Parameters<Obj[keyof Obj]>) => { [Key in keyof Obj]: ReturnType<Obj[Key]> };
457export function applySpec<T>(obj: any): (...args: unknown[]) => T;
458
459/**
460 * Takes a value and applies a function to it.
461 *
462 * This function is also known as the `thrush` combinator.
463 *
464 * @example
465 * ```typescript
466 * const t42 = R.applyTo(42);
467 * t42(R.identity); //=> 42
468 * t42(R.add(1)); //=> 43
469 * ```
470 */
471export function applyTo<T, U>(el: T, fn: (t: T) => U): U;
472export function applyTo<T>(el: T): <U>(fn: (t: T) => U) => U;
473
474/**
475 * Makes an ascending comparator function out of a function that returns a value that can be compared with `<` and `>`.
476 *
477 * See also {@link descend}.
478 *
479 * @example
480 * ```typescript
481 * const byAge = R.ascend(R.prop<'age', number>('age'));
482 * const people = [
483 * { name: 'Emma', age: 70 },
484 * { name: 'Peter', age: 78 },
485 * { name: 'Mikhail', age: 62 },
486 * ];
487 * const peopleByYoungestFirst = R.sort(byAge, people);
488 * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
489 * ```
490 */
491export function ascend<T>(fn: (obj: T) => Ord, a: T, b: T): Ordering;
492export function ascend<T>(fn: (obj: T) => Ord): (a: T, b: T) => Ordering;
493
494/**
495 * Makes a shallow clone of an object, setting or overriding the specified property with the given value.
496 *
497 * @note This copies and flattens prototype properties onto the new object as well.
498 * All non-primitive properties are copied by reference.
499 *
500 * See also {@link dissoc}, {@link pick}.
501 *
502 * @example
503 * ```typescript
504 * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
505 * ```
506 */
507export function assoc<T, U>(__: Placeholder, val: T, obj: U): <K extends string>(prop: K) => Record<K, T> & Omit<U, K>;
508export function assoc<U, K extends string>(prop: K, __: Placeholder, obj: U): <T>(val: T) => Record<K, T> & Omit<U, K>;
509export function assoc<T, U, K extends string>(prop: K, val: T, obj: U): Record<K, T> & Omit<U, K>;
510export function assoc<T, K extends string>(prop: K, val: T): <U>(obj: U) => Record<K, T> & Omit<U, K>;
511export function assoc<K extends string>(prop: K): AssocPartialOne<K>;
512
513/**
514 * Makes a shallow clone of an object,
515 * setting or overriding the nodes required to create the given path,
516 * and placing the specific value at the tail end of that path.
517 *
518 * @note This copies and flattens prototype properties onto the new object as well.
519 * All non-primitive properties are copied by reference.
520 *
521 * See also {@link dissocPath}.
522 *
523 * @example
524 * ```typescript
525 * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
526 *
527 * // Any missing or non-object keys in path will be overridden
528 * R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}}
529 * ```
530 */
531export function assocPath<T, U>(__: Placeholder, val: T, obj: U): (path: Path) => U;
532export function assocPath<T, U>(path: Path, __: Placeholder, obj: U): (val: T) => U;
533export function assocPath<T, U>(path: Path, val: T, obj: U): U;
534export function assocPath<T, U>(path: Path, val: T): (obj: U) => U;
535export function assocPath<T, U>(path: Path): _.F.Curry<(a: T, b: U) => U>;
536
537/**
538 * Wraps a function of any arity (including nullary) in a function that accepts exactly 2
539 * parameters. Any extraneous parameters will not be passed to the supplied function.
540 *
541 * See also {@link nAry}, {@link unary}.
542 *
543 * @example
544 * ```typescript
545 * const takesThreeArgs = function(a: number, b: number, c: number) {
546 * return [a, b, c];
547 * };
548 * takesThreeArgs.length; //=> 3
549 * takesThreeArgs(1, 2, 3); //=> [1, 2, 3]
550 *
551 * const takesTwoArgs = R.binary(takesThreeArgs);
552 * takesTwoArgs.length; //=> 2
553 * // Only 2 arguments are passed to the wrapped function
554 * // @ts-expect-error TypeScript is designed to not let you do this
555 * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
556 * ```
557 */
558export function binary<T extends AnyFunction>(fn: T): (...arg: _.T.Take<Parameters<T>, '2'>) => ReturnType<T>;
559
560/**
561 * Creates a function that is bound to a context.
562 *
563 * @note `R.bind` does not provide the additional argument-binding capabilities of `Function.prototype.bind`.
564 *
565 * @example
566 * ```typescript
567 * const log = R.bind(console.log, console);
568 * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3}
569 * // logs {a: 2}
570 * ```
571 */
572export function bind<F extends AnyFunction, T>(fn: F, thisObj: T): (...args: Parameters<F>) => ReturnType<F>;
573export function bind<F extends AnyFunction, T>(fn: F): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>;
574
575/**
576 * A function which calls the two provided functions and returns the `&&` of the
577 * results. It returns the result of the first function if it is falsy and
578 * the result of the second function otherwise.
579 *
580 * @note This is short-circuited,
581 * meaning that the second function will not be invoked if the first returns a falsy value.
582 *
583 * In addition to functions, `R.both` also accepts any fantasy-land compatible applicative functor.
584 *
585 * See also {@link either}, {@link and}.
586 *
587 * @example
588 * ```typescript
589 * const gt10 = R.gt(R.__, 10)
590 * const lt20 = R.lt(R.__, 20)
591 * const f = R.both(gt10, lt20);
592 * f(15); //=> true
593 * f(30); //=> false
594 * ```
595 */
596export function both<T, TF1 extends T, TF2 extends T>(
597 pred1: PredTypeguard<T, TF1>,
598 pred2: PredTypeguard<T, TF2>,
599): (a: T) => a is TF1 & TF2;
600export function both<T extends Pred>(pred1: T, pred2: T): T;
601export function both<T extends Pred>(pred1: T): (pred2: T) => T;
602
603// NOTE: It is currently difficult to use it as a converging function for `R.converge`
604/**
605 * Returns the result of calling its first argument with the remaining arguments.
606 * This is occasionally useful as a converging function for {@link converge `R.converge`}:
607 * the first branch can produce a function
608 * while the remaining branches produce values to be passed to that function as its arguments.
609 *
610 * See also {@link apply}.
611 *
612 * @example
613 * ```typescript
614 * R.call<(a: number, b: number) => number>(R.add, 1, 2); //=> 3
615 *
616 * const indentN = R.pipe(
617 * R.repeat(' '),
618 * R.join(''),
619 * R.replace(/^(?!$)/gm)
620 * );
621 * ```
622 */
623export function call<T extends AnyFunction>(fn: T, ...args: Parameters<T>): ReturnType<T>;
624
625/**
626 * `chain` maps a function over a list and concatenates the results. `chain` is also known as `flatMap` in some libraries.
627 *
628 * Dispatches to the `chain` method of the second argument, if present, according to the FantasyLand Chain spec.
629 *
630 * If second argument is a function, `chain(f, g)(x)` is equivalent to `f(g(x), x)`.
631 *
632 * Acts as a transducer if a transformer is given in list position.
633 *
634 * See also {@link transduce}.
635 *
636 * @example
637 * ```typescript
638 * const duplicate = <T>(n: T) => [n, n];
639 * R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]
640 *
641 * R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1]
642 * ```
643 */
644export function chain<A, B, T = never>(fn: (n: A) => readonly B[], list: readonly A[]): B[];
645export function chain<A, B, T = never>(fn: (n: A) => readonly B[]): (list: readonly A[]) => B[];
646
647export function chain<A, B, R>(aToMb: (a: A, r: R) => B, Ma: (r: R) => A): (r: R) => B;
648export function chain<A, B, R>(aToMb: (a: A, r: R) => B): (Ma: (r: R) => A) => (r: R) => B;
649
650/**
651 * Restricts a number to be within a range.
652 * Also works for other ordered types such as strings and `Date`s.
653 *
654 * @example
655 * ```typescript
656 * R.clamp(1, 10, -5) // => 1
657 * R.clamp(1, 10, 15) // => 10
658 * R.clamp(1, 10, 4) // => 4
659 * ```
660 */
661export function clamp<T>(min: T, max: T, value: T): T;
662export function clamp<T>(min: T, max: T): (value: T) => T;
663export function clamp<T>(min: T): (max: T, value: T) => T;
664export function clamp<T>(min: T): (max: T) => (value: T) => T;
665
666/**
667 * Creates a deep copy of the source that can be used in place of the source object without retaining any references to it.
668 * The source object may contain (nested) `Array`s and `Object`s, numbers, strings, booleans and `Date`s.
669 * `Functions` are assigned by reference rather than copied.
670 *
671 * Dispatches to a `clone` method if present.
672 *
673 * Note that if the source object has multiple nodes that share a reference,
674 * the returned object will have the same structure,
675 * but the references will be pointed to the location within the cloned value.
676 *
677 * @example
678 * ```typescript
679 * const objects = [{}, {}, {}];
680 * const objectsClone = R.clone(objects);
681 * objects === objectsClone; //=> false
682 * objects[0] === objectsClone[0]; //=> false
683 * ```
684 */
685export function clone<T>(value: T): T;
686export function clone<T>(value: readonly T[]): T[];
687
688/**
689 * Splits a list into sub-lists,
690 * based on the result of calling a key-returning function on each element,
691 * and grouping the results according to values returned.
692 *
693 * See also {@link groupBy}, {@link partition}.
694 *
695 * @example
696 * ```typescript
697 * R.collectBy(R.prop('type'), [
698 * {type: 'breakfast', item: '☕️'},
699 * {type: 'lunch', item: '🌯'},
700 * {type: 'dinner', item: '🍝'},
701 * {type: 'breakfast', item: '🥐'},
702 * {type: 'lunch', item: '🍕'}
703 * ]);
704 *
705 * // [ [ {type: 'breakfast', item: '☕️'},
706 * // {type: 'breakfast', item: '🥐'} ],
707 * // [ {type: 'lunch', item: '🌯'},
708 * // {type: 'lunch', item: '🍕'} ],
709 * // [ {type: 'dinner', item: '🍝'} ] ]
710 * ```
711 */
712export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: readonly T[]): T[][];
713export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K): (list: readonly T[]) => T[][];
714
715/**
716 * Makes a comparator function out of a function that reports whether the first element is less than the second.
717 *
718 * @example
719 * ```typescript
720 * type Person = { name: string; age: number; };
721 *
722 * const byAge = R.comparator<Person>((a, b) => a.age < b.age);
723 * const people = [
724 * { name: 'Emma', age: 70 },
725 * { name: 'Peter', age: 78 },
726 * { name: 'Mikhail', age: 62 },
727 * ];
728 * const peopleByIncreasingAge = R.sort(byAge, people);
729 * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
730 * ```
731 */
732export function comparator<T>(pred: (a: T, b: T) => boolean): (x: T, y: T) => Ordering;
733
734/**
735 * Takes a function `f` and returns a function `g` such that
736 * if called with the same arguments
737 * when `f` returns a truthy value, `g` returns `false`
738 * and when `f` returns a falsy value `g` returns `true`.
739 *
740 * `R.complement` may be applied to any functor.
741 *
742 * See also {@link not}.
743 *
744 * @example
745 * ```typescript
746 * const isNotNil = R.complement(R.isNil);
747 * R.isNil(null); //=> true
748 * isNotNil(null); //=> false
749 * R.isNil(7); //=> false
750 * isNotNil(7); //=> true
751 * ```
752 */
753export function complement<T, TFiltered extends T>(
754 pred: (value: T) => value is TFiltered,
755): (value: T) => value is Exclude<T, TFiltered>;
756export function complement<TArgs extends any[]>(pred: (...args: TArgs) => unknown): (...args: TArgs) => boolean;
757
758/**
759 * Performs right-to-left function composition.
760 * The rightmost function may have any arity;
761 * the remaining functions must be unary.
762 *
763 * @note The result of `R.compose` is not automatically curried.
764 *
765 * See also {@link pipe}.
766 *
767 * @example
768 * ```typescript
769 * const classyGreeting = (firstName: string, lastName: string) => "The name's " + lastName + ", " + firstName + " " + lastName
770 * const yellGreeting = R.compose(R.toUpper, classyGreeting);
771 * yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND"
772 *
773 * R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7
774 * ```
775 */
776export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
777 ...func: [
778 fnLast: (a: any) => TResult,
779 ...func: Array<(a: any) => any>,
780 f7: (a: R6) => R7,
781 f6: (a: R5) => R6,
782 f5: (a: R4) => R5,
783 f4: (a: R3) => R4,
784 f3: (a: R2) => R3,
785 f2: (a: R1) => R2,
786 f1: (...args: TArgs) => R1,
787 ]
788): (...args: TArgs) => TResult; // fallback overload if number of composed functions greater than 7
789export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
790 f7: (a: R6) => R7,
791 f6: (a: R5) => R6,
792 f5: (a: R4) => R5,
793 f4: (a: R3) => R4,
794 f3: (a: R2) => R3,
795 f2: (a: R1) => R2,
796 f1: (...args: TArgs) => R1,
797): (...args: TArgs) => R7;
798export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
799 f7: (a: R6) => R7,
800 f6: (a: R5) => R6,
801 f5: (a: R4) => R5,
802 f4: (a: R3) => R4,
803 f3: (a: R2) => R3,
804 f2: (a: R1) => R2,
805 f1: (...args: TArgs) => R1,
806): (...args: TArgs) => R7;
807export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
808 f6: (a: R5) => R6,
809 f5: (a: R4) => R5,
810 f4: (a: R3) => R4,
811 f3: (a: R2) => R3,
812 f2: (a: R1) => R2,
813 f1: (...args: TArgs) => R1,
814): (...args: TArgs) => R6;
815export function compose<TArgs extends any[], R1, R2, R3, R4, R5>(
816 f5: (a: R4) => R5,
817 f4: (a: R3) => R4,
818 f3: (a: R2) => R3,
819 f2: (a: R1) => R2,
820 f1: (...args: TArgs) => R1,
821): (...args: TArgs) => R5;
822export function compose<TArgs extends any[], R1, R2, R3, R4>(
823 f4: (a: R3) => R4,
824 f3: (a: R2) => R3,
825 f2: (a: R1) => R2,
826 f1: (...args: TArgs) => R1,
827): (...args: TArgs) => R4;
828export function compose<TArgs extends any[], R1, R2, R3>(
829 f3: (a: R2) => R3,
830 f2: (a: R1) => R2,
831 f1: (...args: TArgs) => R1,
832): (...args: TArgs) => R3;
833export function compose<TArgs extends any[], R1, R2>(
834 f2: (a: R1) => R2,
835 f1: (...args: TArgs) => R1,
836): (...args: TArgs) => R2;
837export function compose<TArgs extends any[], R1>(f1: (...args: TArgs) => R1): (...args: TArgs) => R1;
838
839/**
840 * Returns the right-to-left Kleisli composition of the provided functions, each of which must return a value of a type supported by chain.
841 * The typings only support arrays for now.
842 * All functions must be unary.
843 * R.composeK(h, g, f) is equivalent to R.compose(R.chain(h), R.chain(g), f).
844 *
845 * @deprecated since 0.26 in favor of composeWith(chain)
846 */
847export function composeK<V0, T1>(fn0: (x0: V0) => T1[]): (x0: V0) => T1[];
848export function composeK<V0, T1, T2>(fn1: (x: T1) => T2[], fn0: (x0: V0) => T1[]): (x0: V0) => T2[];
849export function composeK<V0, T1, T2, T3>(
850 fn2: (x: T2) => T3[],
851 fn1: (x: T1) => T2[],
852 fn0: (x: V0) => T1[],
853): (x: V0) => T3[];
854export function composeK<V0, T1, T2, T3, T4>(
855 fn3: (x: T3) => T4[],
856 fn2: (x: T2) => T3[],
857 fn1: (x: T1) => T2[],
858 fn0: (x: V0) => T1[],
859): (x: V0) => T4[];
860export function composeK<V0, T1, T2, T3, T4, T5>(
861 fn4: (x: T4) => T5[],
862 fn3: (x: T3) => T4[],
863 fn2: (x: T2) => T3[],
864 fn1: (x: T1) => T2[],
865 fn0: (x: V0) => T1[],
866): (x: V0) => T5[];
867export function composeK<V0, T1, T2, T3, T4, T5, T6>(
868 fn5: (x: T5) => T6[],
869 fn4: (x: T4) => T5[],
870 fn3: (x: T3) => T4[],
871 fn2: (x: T2) => T3[],
872 fn1: (x: T1) => T2[],
873 fn0: (x: V0) => T1[],
874): (x: V0) => T6[];
875
876/**
877 * Performs right-to-left composition of one or more Promise-returning functions.
878 * All functions must be unary.
879 *
880 * @deprecated since 0.26 in favor of composeWith(then)
881 */
882export function composeP<V0, T1>(fn0: (x0: V0) => Promise<T1>): (x0: V0) => Promise<T1>;
883export function composeP<V0, T1, T2>(
884 fn1: (x: T1) => Promise<T2>,
885 fn0: (x0: V0) => Promise<T1>,
886): (x0: V0) => Promise<T2>;
887export function composeP<V0, T1, T2, T3>(
888 fn2: (x: T2) => Promise<T3>,
889 fn1: (x: T1) => Promise<T2>,
890 fn0: (x: V0) => Promise<T1>,
891): (x: V0) => Promise<T3>;
892export function composeP<V0, T1, T2, T3, T4>(
893 fn3: (x: T3) => Promise<T4>,
894 fn2: (x: T2) => Promise<T3>,
895 fn1: (x: T1) => Promise<T2>,
896 fn0: (x: V0) => Promise<T1>,
897): (x: V0) => Promise<T4>;
898export function composeP<V0, T1, T2, T3, T4, T5>(
899 fn4: (x: T4) => Promise<T5>,
900 fn3: (x: T3) => Promise<T4>,
901 fn2: (x: T2) => Promise<T3>,
902 fn1: (x: T1) => Promise<T2>,
903 fn0: (x: V0) => Promise<T1>,
904): (x: V0) => Promise<T5>;
905export function composeP<V0, T1, T2, T3, T4, T5, T6>(
906 fn5: (x: T5) => Promise<T6>,
907 fn4: (x: T4) => Promise<T5>,
908 fn3: (x: T3) => Promise<T4>,
909 fn2: (x: T2) => Promise<T3>,
910 fn1: (x: T1) => Promise<T2>,
911 fn0: (x: V0) => Promise<T1>,
912): (x: V0) => Promise<T6>;
913
914/**
915 * Performs right-to-left function composition using transforming function.
916 * The last function may have any arity; the remaining functions must be unary.
917 *
918 * @note The result of `R.composeWith` is not automatically curried.
919 * The transforming function is not used on the last argument.
920 *
921 * See also {@link compose}, {@link pipeWith}.
922 *
923 * @example
924 * ```typescript
925 * const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
926 *
927 * composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
928 * ```
929 */
930export function composeWith<TArgs extends any[], TResult>(
931 transformer: (fn: AnyFunction, intermediatResult: any) => any,
932 fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
933): (...args: TArgs) => TResult;
934export function composeWith(
935 transformer: (fn: AnyFunction, intermediatResult: any) => any,
936): <TArgs extends any[], TResult>(
937 fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
938) => (...args: TArgs) => TResult;
939
940/**
941 * Returns the result of concatenating the given lists or strings.
942 *
943 * @note `R.concat` expects both arguments to be of the same type,
944 * unlike the native `Array.prototype.concat` method.
945 * It will throw an error if you concat an `Array` with a non-`Array` value.
946 *
947 * Dispatches to the `concat` method of the first argument, if present.
948 * Can also concatenate two members of a fantasy-land compatible semigroup.
949 *
950 * @example
951 * ```typescript
952 * R.concat('ABC', 'DEF'); // 'ABCDEF'
953 * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
954 * R.concat([], []); //=> []
955 * ```
956 */
957export function concat(
958 placeholder: Placeholder,
959): (<L1 extends any[], L2 extends any[]>(list1: L1, list2: L2) => [...L1, ...L2]) &
960 (<S1 extends string, S2 extends string>(s1: S1, s2: S2) => `${S1}${S2}`);
961export function concat<L2 extends any[]>(
962 placeholder: Placeholder,
963 list2: L2,
964): <L1 extends any[]>(list1: L1) => [...L1, ...L2];
965export function concat<S2 extends string>(
966 placeholder: Placeholder,
967 s2: S2,
968): <S1 extends string>(s1: S1) => `${S1}${S2}`;
969export function concat<L1 extends any[]>(list1: L1): <L2 extends any[]>(list2: L2) => [...L1, ...L2];
970export function concat<S1 extends string>(s1: S1): <S2 extends string>(s2: S2) => `${S1}${S2}`;
971export function concat<L1 extends any[], L2 extends any[]>(list1: L1, list2: L2): [...L1, ...L2];
972export function concat<S1 extends string, S2 extends string>(s1: S1, s2: S2): `${S1}${S2}`;
973export function concat(s1: string, s2: string): string;
974export function concat(s1: string): (s2: string) => string;
975
976/**
977 * Returns a function, `fn`, which encapsulates `if/else, if/else, ...` logic.
978 * `R.cond` takes a list of [predicate, transformer] pairs. All of the arguments
979 * to `fn` are applied to each of the predicates in turn until one returns a
980 * "truthy" value, at which point `fn` returns the result of applying its
981 * arguments to the corresponding transformer. If none of the predicates
982 * matches, `fn` returns undefined.
983 *
984 * @note This is not a direct substitute for a `switch` statement.
985 * Remember that both elements of every pair passed to `cond` are *functions*,
986 * and `cond` returns a function.
987 *
988 * @note When using this function with a typeguard as predicate,
989 * **all** predicates in all pairs must be typeguards.
990 *
991 * See also {@link ifElse}, {@link unless}, {@link when}.
992 *
993 * @example
994 * ```typescript
995 * const fn = R.cond([
996 * [R.equals(0), R.always('water freezes at 0°C')],
997 * [R.equals(100), R.always('water boils at 100°C')],
998 * [R.T, temp => 'nothing special happens at ' + temp + '°C']
999 * ]);
1000 * fn(0); //=> 'water freezes at 0°C'
1001 * fn(50); //=> 'nothing special happens at 50°C'
1002 * fn(100); //=> 'water boils at 100°C'
1003 * ```
1004 */
1005export function cond<T, TF1 extends T, R>(pairs: [CondPairTypeguard<T, TF1, R>]): (value: T) => R;
1006export function cond<T, TF1 extends T, TF2 extends T, R>(
1007 pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>],
1008): (value: T) => R;
1009export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, R>(
1010 pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>, CondPairTypeguard<T, TF3, R>],
1011): (value: T) => R;
1012export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, R>(
1013 pairs: [
1014 CondPairTypeguard<T, TF1, R>,
1015 CondPairTypeguard<T, TF2, R>,
1016 CondPairTypeguard<T, TF3, R>,
1017 CondPairTypeguard<T, TF4, R>,
1018 ],
1019): (value: T) => R;
1020export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, R>(
1021 pairs: [
1022 CondPairTypeguard<T, TF1, R>,
1023 CondPairTypeguard<T, TF2, R>,
1024 CondPairTypeguard<T, TF3, R>,
1025 CondPairTypeguard<T, TF4, R>,
1026 CondPairTypeguard<T, TF5, R>,
1027 ],
1028): (value: T) => R;
1029export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T, R>(
1030 pairs: [
1031 CondPairTypeguard<T, TF1, R>,
1032 CondPairTypeguard<T, TF2, R>,
1033 CondPairTypeguard<T, TF3, R>,
1034 CondPairTypeguard<T, TF4, R>,
1035 CondPairTypeguard<T, TF5, R>,
1036 CondPairTypeguard<T, TF6, R>,
1037 ],
1038): (value: T) => R;
1039export function cond<
1040 T,
1041 TF1 extends T,
1042 TF2 extends T,
1043 TF3 extends T,
1044 TF4 extends T,
1045 TF5 extends T,
1046 TF6 extends T,
1047 TF7 extends T,
1048 R,
1049>(
1050 pairs: [
1051 CondPairTypeguard<T, TF1, R>,
1052 CondPairTypeguard<T, TF2, R>,
1053 CondPairTypeguard<T, TF3, R>,
1054 CondPairTypeguard<T, TF4, R>,
1055 CondPairTypeguard<T, TF5, R>,
1056 CondPairTypeguard<T, TF6, R>,
1057 CondPairTypeguard<T, TF7, R>,
1058 ],
1059): (value: T) => R;
1060export function cond<
1061 T,
1062 TF1 extends T,
1063 TF2 extends T,
1064 TF3 extends T,
1065 TF4 extends T,
1066 TF5 extends T,
1067 TF6 extends T,
1068 TF7 extends T,
1069 TF8 extends T,
1070 R,
1071>(
1072 pairs: [
1073 CondPairTypeguard<T, TF1, R>,
1074 CondPairTypeguard<T, TF2, R>,
1075 CondPairTypeguard<T, TF3, R>,
1076 CondPairTypeguard<T, TF4, R>,
1077 CondPairTypeguard<T, TF5, R>,
1078 CondPairTypeguard<T, TF6, R>,
1079 CondPairTypeguard<T, TF7, R>,
1080 CondPairTypeguard<T, TF8, R>,
1081 ],
1082): (value: T) => R;
1083export function cond<
1084 T,
1085 TF1 extends T,
1086 TF2 extends T,
1087 TF3 extends T,
1088 TF4 extends T,
1089 TF5 extends T,
1090 TF6 extends T,
1091 TF7 extends T,
1092 TF8 extends T,
1093 TF9 extends T,
1094 R,
1095>(
1096 pairs: [
1097 CondPairTypeguard<T, TF1, R>,
1098 CondPairTypeguard<T, TF2, R>,
1099 CondPairTypeguard<T, TF3, R>,
1100 CondPairTypeguard<T, TF4, R>,
1101 CondPairTypeguard<T, TF5, R>,
1102 CondPairTypeguard<T, TF6, R>,
1103 CondPairTypeguard<T, TF7, R>,
1104 CondPairTypeguard<T, TF8, R>,
1105 CondPairTypeguard<T, TF9, R>,
1106 ],
1107): (value: T) => R;
1108export function cond<
1109 T,
1110 TF1 extends T,
1111 TF2 extends T,
1112 TF3 extends T,
1113 TF4 extends T,
1114 TF5 extends T,
1115 TF6 extends T,
1116 TF7 extends T,
1117 TF8 extends T,
1118 TF9 extends T,
1119 TF10 extends T,
1120 R,
1121>(
1122 pairs: [
1123 CondPairTypeguard<T, TF1, R>,
1124 CondPairTypeguard<T, TF2, R>,
1125 CondPairTypeguard<T, TF3, R>,
1126 CondPairTypeguard<T, TF4, R>,
1127 CondPairTypeguard<T, TF5, R>,
1128 CondPairTypeguard<T, TF6, R>,
1129 CondPairTypeguard<T, TF7, R>,
1130 CondPairTypeguard<T, TF8, R>,
1131 CondPairTypeguard<T, TF9, R>,
1132 CondPairTypeguard<T, TF10, R>,
1133 ],
1134): (value: T) => R;
1135export function cond<T extends any[], R>(pairs: ReadonlyArray<CondPair<T, R>>): (...args: T) => R;
1136
1137/**
1138 * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
1139 *
1140 * See also {@link invoker}.
1141 *
1142 * @example
1143 * ```typescript
1144 * // Constructor function
1145 * class Animal {
1146 * constructor(public kind: string) {}
1147 *
1148 * sighting() {
1149 * return "It's a " + this.kind + "!";
1150 * }
1151 * }
1152 *
1153 * const AnimalConstructor = R.construct(Animal)
1154 *
1155 * // Notice we no longer need the 'new' keyword:
1156 * AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}};
1157 *
1158 * const animalTypes = ["Lion", "Tiger", "Bear"];
1159 * const animalSighting = R.invoker(0, 'sighting');
1160 * const sightNewAnimal = R.compose(animalSighting, AnimalConstructor);
1161 * R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"]
1162 * ```
1163 */
1164export function construct<A extends any[], T>(
1165 constructor: { new (...args: A): T } | ((...args: A) => T),
1166): _.F.Curry<(...args: A) => T>;
1167
1168// NOTE: Example doesn't work with this typing
1169/**
1170 * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
1171 * The arity of the function returned is specified to allow using variadic constructor functions.
1172 */
1173export function constructN<A extends any[], T, N extends number>(
1174 n: N,
1175 constructor: { new (...args: A): T } | ((...args: A) => T),
1176): _.F.Curry<(...args: mergeArrWithLeft<Tuple<any, N>, A>) => T>;
1177
1178/**
1179 * Returns `true` if the specified item is somewhere in the list, `false` otherwise.
1180 * Equivalent to `indexOf(a)(list) > -1`. Uses strict (`===`) equality checking.
1181 *
1182 * @deprecated since 0.26 in favor of includes
1183 */
1184export function contains(__: Placeholder, list: string): (a: string) => boolean;
1185export function contains<T>(__: Placeholder, list: readonly T[]): (a: T) => boolean;
1186export function contains(__: Placeholder): (list: string, a: string) => boolean;
1187export function contains<T>(__: Placeholder): (list: readonly T[], a: T) => boolean;
1188export function contains(a: string, list: string): boolean;
1189export function contains<T>(a: T, list: readonly T[]): boolean;
1190export function contains(a: string): (list: string) => boolean;
1191export function contains<T>(a: T): (list: readonly T[]) => boolean;
1192
1193// NOTE: Example doesn't work with this typing
1194/**
1195 * Accepts a converging function and a list of branching functions and returns a new function.
1196 * When invoked, this new function is applied to some arguments,
1197 * each branching function is applied to those same arguments.
1198 * The results of each branching function are passed as arguments to the converging function
1199 * to produce the return value.
1200 *
1201 * See also {@link useWith}.
1202 */
1203export function converge<
1204 TResult,
1205 FunctionsList extends ReadonlyArray<Fn> &
1206 IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
1207 _Fns extends ReadonlyArray<Fn> = FunctionsList,
1208>(
1209 converging: (...args: ReturnTypesOfFns<FunctionsList>) => TResult,
1210 branches: FunctionsList,
1211): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
1212export function converge<
1213 CArgs extends ReadonlyArray<any>,
1214 TResult,
1215 FunctionsList extends readonly [
1216 ...{
1217 [Index in keyof CArgs]: (...args: ReadonlyArray<any>) => CArgs[Index];
1218 },
1219 ] &
1220 IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
1221 _Fns extends ReadonlyArray<Fn> = FunctionsList,
1222>(
1223 converging: (...args: CArgs) => TResult,
1224 branches: FunctionsList,
1225): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
1226
1227/**
1228 * Returns the number of items in a given `list` matching the predicate `f`.
1229 *
1230 * @example
1231 * ```typescript
1232 * const even = (x: number) => x % 2 == 0;
1233 *
1234 * R.count(even, [1, 2, 3, 4, 5]); // => 2
1235 * R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
1236 * ```
1237 */
1238export function count<T>(fn: (a: T) => boolean, list: readonly T[]): number;
1239export function count<T>(fn: (a: T) => boolean): (list: readonly T[]) => number;
1240
1241/**
1242 * Counts the elements of a list according to how many match each value of a key generated by the supplied function.
1243 * Returns an object mapping the keys produced by `fn` to the number of occurrences in the list.
1244 * Note that all keys are coerced to strings because of how JavaScript objects work.
1245 *
1246 * Acts as a transducer if a transformer is given in list position.
1247 *
1248 * See also {@link transduce}.
1249 *
1250 * @example
1251 * ```typescript
1252 * const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
1253 * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
1254 *
1255 * const letters = ['a', 'b', 'A', 'a', 'B', 'c'];
1256 * R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1}
1257 * ```
1258 */
1259export function countBy<T>(fn: (a: T) => string | number, list: readonly T[]): { [index: string]: number };
1260export function countBy<T>(fn: (a: T) => string | number): (list: readonly T[]) => { [index: string]: number };
1261
1262/**
1263 * Returns a curried equivalent of the provided function.
1264 *
1265 * See also {@link curryN}, {@link partial}.
1266 *
1267 * The curried function has two unusual capabilities.
1268 *
1269 * First, its arguments needn't be provided one at a time.
1270 * If `f` is a ternary function and `g` is `R.curry(f)`, the following are equivalent:
1271 * - `g(1)(2)(3)`
1272 * - `g(1)(2, 3)`
1273 * - `g(1, 2)(3)`
1274 * - `g(1, 2, 3)`
1275 *
1276 * Secondly, the special placeholder value `R.__` may be used to specify "gaps",
1277 * allowing partial application of any combination of arguments,
1278 * regardless of their positions.
1279 * If `g` is as above and `_` is `R.__`, the following are equivalent:
1280 * - `g(1, 2, 3)`
1281 * - `g(_, 2, 3)(1)`
1282 * - `g(_, _, 3)(1)(2)`
1283 * - `g(_, _, 3)(1, 2)`
1284 * - `g(_, 2)(1)(3)`
1285 * - `g(_, 2)(1, 3)`
1286 * - `g(_, 2)(_, 3)(1)`
1287 *
1288 * @example
1289 * ```typescript
1290 * const addFourNumbers = (a: number, b: number, c: number, d: number) => a + b + c + d;
1291 *
1292 * const curriedAddFourNumbers = R.curry(addFourNumbers);
1293 * const f = curriedAddFourNumbers(1, 2);
1294 * const g = f(3);
1295 * g(4); //=> 10
1296 * ```
1297 */
1298export function curry<F extends AnyFunction>(f: F): _.F.Curry<F>;
1299
1300/**
1301 * Returns a curried equivalent of the provided function, with the specified arity.
1302 *
1303 * See also {@link curry}.
1304 *
1305 * The curried function has two unusual capabilities.
1306 *
1307 * First, its arguments needn't be provided one at a time.
1308 * If `f` is a ternary function and `g` is `R.curry(f)`, the following are equivalent:
1309 * - `g(1)(2)(3)`
1310 * - `g(1)(2, 3)`
1311 * - `g(1, 2)(3)`
1312 * - `g(1, 2, 3)`
1313 *
1314 * Secondly, the special placeholder value `R.__` may be used to specify "gaps",
1315 * allowing partial application of any combination of arguments,
1316 * regardless of their positions.
1317 * If `g` is as above and `_` is `R.__`, the following are equivalent:
1318 * - `g(1, 2, 3)`
1319 * - `g(_, 2, 3)(1)`
1320 * - `g(_, _, 3)(1)(2)`
1321 * - `g(_, _, 3)(1, 2)`
1322 * - `g(_, 2)(1)(3)`
1323 * - `g(_, 2)(1, 3)`
1324 * - `g(_, 2)(_, 3)(1)`
1325 *
1326 * @example
1327 * ```typescript
1328 * const sumArgs = (...args: number[]) => R.sum(args);
1329 *
1330 * const curriedAddFourNumbers = R.curryN(4, sumArgs);
1331 * const f = curriedAddFourNumbers(1, 2);
1332 * const g = f(3);
1333 * g(4); //=> 10
1334 * ```
1335 */
1336export function curryN<N extends number, F extends AnyFunction>(
1337 length: N,
1338 fn: F,
1339): _.F.Curry<(...args: _.T.Take<Parameters<F>, _.N.NumberOf<N>>) => ReturnType<F>>;
1340export function curryN<N extends number>(
1341 length: N,
1342): <F extends AnyFunction>(fn: F) => _.F.Curry<(...args: _.T.Take<Parameters<F>, _.N.NumberOf<N>>) => ReturnType<F>>;
1343
1344/**
1345 * Decrements its argument.
1346 *
1347 * See also {@link inc}.
1348 *
1349 * @example
1350 * ```typescript
1351 * R.dec(42); //=> 41
1352 * ```
1353 */