UNPKG

206 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// John Ottenlips <https://github.com/jottenlips>
21// Nitesh Phadatare <https://github.com/minitesh>
22// Krantisinh Deshmukh <https://github.com/krantisinh>
23// Aram Kharazyan <https://github.com/nemo108>
24// Jituan Lin <https://github.com/jituanlin>
25// Philippe Mills <https://github.com/Philippe-mills>
26// Saul Mirone <https://github.com/Saul-Mirone>
27// Nicholai Nissen <https://github.com/Nicholaiii>
28// Jorge Santana <https://github.com/LORDBABUINO>
29// Mikael Couzic <https://github.com/couzic>
30// Nikita Balikhin <https://github.com/NEWESTERS>
31// Wang Zengdi <https://github.com/adispring>
32// Marcus Blättermann <https://github.com/essenmitsosse>
33// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
34// TypeScript Version: 4.2
35
36import * as _ from 'ts-toolbelt';
37import {
38 AnyConstructor,
39 AnyFunction,
40 AtLeastOneFunctionsFlow,
41 AtLeastOneFunctionsFlowFromRightToLeft,
42 AssocPartialOne,
43 CondPair,
44 CondPairTypeguard,
45 Dictionary,
46 Evolvable,
47 Evolve,
48 Evolver,
49 Falsy,
50 Find,
51 Functor,
52 InputTypesOfFns,
53 KeyValuePair,
54 Lens,
55 Merge,
56 MergeAll,
57 ObjectHavingSome,
58 ObjPred,
59 Ord,
60 Ordering,
61 Path,
62 Placeholder,
63 Pred,
64 PredTypeguard,
65 Reduced,
66 ReturnTypesOfFns,
67 ValueOfUnion,
68 Take,
69 ToTupleOfArray,
70 ToTupleOfFunction,
71 Tuple,
72 Fn,
73 IfFunctionsArgumentsDoNotOverlap,
74 LargestArgumentsList,
75 mergeArrWithLeft,
76 Prop,
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<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) => K extends keyof U ? T extends U[K] ? U : Record<K, T> & Omit<U, K> : Record<K, T> & Omit<U, K>;
508export function assoc<U, K extends keyof U>(prop: K, __: Placeholder, obj: U): <T>(val: T) => T extends U[K] ? U : Record<K, T> & Omit<U, K>;
509export function assoc<U, K extends string>(prop: K, __: Placeholder, obj: U): <T>(val: T) => Record<K, T> & Omit<U, K>;
510export function assoc<K extends keyof U, U>(prop: K, val: U[K], obj: U): U;
511export function assoc<T, U, K extends string>(prop: K, val: T, obj: U): Record<K, T> & Omit<U, K>;
512export function assoc<T, K extends string>(prop: K, val: T): <U>(obj: U) => Record<K, T> & Omit<U, K>;
513export function assoc<K extends string>(prop: K): AssocPartialOne<K>;
514
515/**
516 * Makes a shallow clone of an object,
517 * setting or overriding the nodes required to create the given path,
518 * and placing the specific value at the tail end of that path.
519 *
520 * @note This copies and flattens prototype properties onto the new object as well.
521 * All non-primitive properties are copied by reference.
522 *
523 * See also {@link dissocPath}.
524 *
525 * @example
526 * ```typescript
527 * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
528 *
529 * // Any missing or non-object keys in path will be overridden
530 * R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}}
531 * ```
532 */
533export function assocPath<T, U>(__: Placeholder, val: T, obj: U): (path: Path) => U;
534export function assocPath<T, U>(path: Path, __: Placeholder, obj: U): (val: T) => U;
535export function assocPath<T, U>(path: Path, val: T, obj: U): U;
536export function assocPath<T, U>(path: Path, val: T): (obj: U) => U;
537export function assocPath<T, U>(path: Path): _.F.Curry<(a: T, b: U) => U>;
538
539/**
540 * Wraps a function of any arity (including nullary) in a function that accepts exactly 2
541 * parameters. Any extraneous parameters will not be passed to the supplied function.
542 *
543 * See also {@link nAry}, {@link unary}.
544 *
545 * @example
546 * ```typescript
547 * const takesThreeArgs = function(a: number, b: number, c: number) {
548 * return [a, b, c];
549 * };
550 * takesThreeArgs.length; //=> 3
551 * takesThreeArgs(1, 2, 3); //=> [1, 2, 3]
552 *
553 * const takesTwoArgs = R.binary(takesThreeArgs);
554 * takesTwoArgs.length; //=> 2
555 * // Only 2 arguments are passed to the wrapped function
556 * // @ts-expect-error TypeScript is designed to not let you do this
557 * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
558 * ```
559 */
560export function binary<T extends AnyFunction>(fn: T): (...arg: _.T.Take<Parameters<T>, '2'>) => ReturnType<T>;
561
562/**
563 * Creates a function that is bound to a context.
564 *
565 * @note `R.bind` does not provide the additional argument-binding capabilities of `Function.prototype.bind`.
566 *
567 * @example
568 * ```typescript
569 * const log = R.bind(console.log, console);
570 * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3}
571 * // logs {a: 2}
572 * ```
573 */
574export function bind<F extends AnyFunction, T>(fn: F, thisObj: T): (...args: Parameters<F>) => ReturnType<F>;
575export function bind<F extends AnyFunction, T>(fn: F): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>;
576
577/**
578 * A function which calls the two provided functions and returns the `&&` of the
579 * results. It returns the result of the first function if it is falsy and
580 * the result of the second function otherwise.
581 *
582 * @note This is short-circuited,
583 * meaning that the second function will not be invoked if the first returns a falsy value.
584 *
585 * In addition to functions, `R.both` also accepts any fantasy-land compatible applicative functor.
586 *
587 * See also {@link either}, {@link and}.
588 *
589 * @example
590 * ```typescript
591 * const gt10 = R.gt(R.__, 10)
592 * const lt20 = R.lt(R.__, 20)
593 * const f = R.both(gt10, lt20);
594 * f(15); //=> true
595 * f(30); //=> false
596 * ```
597 */
598export function both<T, TF1 extends T, TF2 extends T>(
599 pred1: PredTypeguard<T, TF1>,
600 pred2: PredTypeguard<T, TF2>,
601): (a: T) => a is TF1 & TF2;
602export function both<T extends Pred>(pred1: T, pred2: T): T;
603export function both<T extends Pred>(pred1: T): (pred2: T) => T;
604
605// NOTE: It is currently difficult to use it as a converging function for `R.converge`
606/**
607 * Returns the result of calling its first argument with the remaining arguments.
608 * This is occasionally useful as a converging function for {@link converge `R.converge`}:
609 * the first branch can produce a function
610 * while the remaining branches produce values to be passed to that function as its arguments.
611 *
612 * See also {@link apply}.
613 *
614 * @example
615 * ```typescript
616 * R.call<(a: number, b: number) => number>(R.add, 1, 2); //=> 3
617 *
618 * const indentN = R.pipe(
619 * R.repeat(' '),
620 * R.join(''),
621 * R.replace(/^(?!$)/gm)
622 * );
623 * ```
624 */
625export function call<T extends AnyFunction>(fn: T, ...args: Parameters<T>): ReturnType<T>;
626
627/**
628 * `chain` maps a function over a list and concatenates the results. `chain` is also known as `flatMap` in some libraries.
629 *
630 * Dispatches to the `chain` method of the second argument, if present, according to the FantasyLand Chain spec.
631 *
632 * If second argument is a function, `chain(f, g)(x)` is equivalent to `f(g(x), x)`.
633 *
634 * Acts as a transducer if a transformer is given in list position.
635 *
636 * See also {@link transduce}.
637 *
638 * @example
639 * ```typescript
640 * const duplicate = <T>(n: T) => [n, n];
641 * R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]
642 *
643 * R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1]
644 * ```
645 */
646export function chain<A, B, T = never>(fn: (n: A) => readonly B[], list: readonly A[]): B[];
647export function chain<A, B, T = never>(fn: (n: A) => readonly B[]): (list: readonly A[]) => B[];
648
649export function chain<A, Ma extends { chain: (fn: (a: A) => Mb) => Mb }, Mb>(fn: (a: A) => Mb, monad: Ma): Mb;
650export function chain<A, Ma extends { chain: (fn: (a: A) => Mb) => Mb }, Mb>(fn: (a: A) => Mb): (monad: Ma) => Mb;
651
652export function chain<A, B, R>(aToMb: (a: A, r: R) => B, Ma: (r: R) => A): (r: R) => B;
653export function chain<A, B, R>(aToMb: (a: A, r: R) => B): (Ma: (r: R) => A) => (r: R) => B;
654
655/**
656 * Restricts a number to be within a range.
657 * Also works for other ordered types such as strings and `Date`s.
658 *
659 * @example
660 * ```typescript
661 * R.clamp(1, 10, -5) // => 1
662 * R.clamp(1, 10, 15) // => 10
663 * R.clamp(1, 10, 4) // => 4
664 * ```
665 */
666export function clamp<T>(min: T, max: T, value: T): T;
667export function clamp<T>(min: T, max: T): (value: T) => T;
668export function clamp<T>(min: T): (max: T, value: T) => T;
669export function clamp<T>(min: T): (max: T) => (value: T) => T;
670
671/**
672 * Creates a deep copy of the source that can be used in place of the source object without retaining any references to it.
673 * The source object may contain (nested) `Array`s and `Object`s, numbers, strings, booleans and `Date`s.
674 * `Functions` are assigned by reference rather than copied.
675 *
676 * Dispatches to a `clone` method if present.
677 *
678 * Note that if the source object has multiple nodes that share a reference,
679 * the returned object will have the same structure,
680 * but the references will be pointed to the location within the cloned value.
681 *
682 * @example
683 * ```typescript
684 * const objects = [{}, {}, {}];
685 * const objectsClone = R.clone(objects);
686 * objects === objectsClone; //=> false
687 * objects[0] === objectsClone[0]; //=> false
688 * ```
689 */
690export function clone<T>(value: T): T;
691export function clone<T>(value: readonly T[]): T[];
692
693/**
694 * Splits a list into sub-lists,
695 * based on the result of calling a key-returning function on each element,
696 * and grouping the results according to values returned.
697 *
698 * See also {@link groupBy}, {@link partition}.
699 *
700 * @example
701 * ```typescript
702 * R.collectBy(R.prop('type'), [
703 * {type: 'breakfast', item: '☕️'},
704 * {type: 'lunch', item: '🌯'},
705 * {type: 'dinner', item: '🍝'},
706 * {type: 'breakfast', item: '🥐'},
707 * {type: 'lunch', item: '🍕'}
708 * ]);
709 *
710 * // [ [ {type: 'breakfast', item: '☕️'},
711 * // {type: 'breakfast', item: '🥐'} ],
712 * // [ {type: 'lunch', item: '🌯'},
713 * // {type: 'lunch', item: '🍕'} ],
714 * // [ {type: 'dinner', item: '🍝'} ] ]
715 * ```
716 */
717export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: readonly T[]): T[][];
718export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K): (list: readonly T[]) => T[][];
719
720/**
721 * Makes a comparator function out of a function that reports whether the first element is less than the second.
722 *
723 * @example
724 * ```typescript
725 * type Person = { name: string; age: number; };
726 *
727 * const byAge = R.comparator<Person>((a, b) => a.age < b.age);
728 * const people = [
729 * { name: 'Emma', age: 70 },
730 * { name: 'Peter', age: 78 },
731 * { name: 'Mikhail', age: 62 },
732 * ];
733 * const peopleByIncreasingAge = R.sort(byAge, people);
734 * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
735 * ```
736 */
737export function comparator<T>(pred: (a: T, b: T) => boolean): (x: T, y: T) => Ordering;
738
739/**
740 * Takes a function `f` and returns a function `g` such that
741 * if called with the same arguments
742 * when `f` returns a truthy value, `g` returns `false`
743 * and when `f` returns a falsy value `g` returns `true`.
744 *
745 * `R.complement` may be applied to any functor.
746 *
747 * See also {@link not}.
748 *
749 * @example
750 * ```typescript
751 * const isNotNil = R.complement(R.isNil);
752 * R.isNil(null); //=> true
753 * isNotNil(null); //=> false
754 * R.isNil(7); //=> false
755 * isNotNil(7); //=> true
756 * ```
757 */
758export function complement<T, TFiltered extends T>(
759 pred: (value: T) => value is TFiltered,
760): (value: T) => value is Exclude<T, TFiltered>;
761export function complement<TArgs extends any[]>(pred: (...args: TArgs) => unknown): (...args: TArgs) => boolean;
762
763/**
764 * Performs right-to-left function composition.
765 * The rightmost function may have any arity;
766 * the remaining functions must be unary.
767 *
768 * @note The result of `R.compose` is not automatically curried.
769 *
770 * See also {@link pipe}.
771 *
772 * @example
773 * ```typescript
774 * const classyGreeting = (firstName: string, lastName: string) => "The name's " + lastName + ", " + firstName + " " + lastName
775 * const yellGreeting = R.compose(R.toUpper, classyGreeting);
776 * yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND"
777 *
778 * R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7
779 * ```
780 */
781export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
782 ...func: [
783 fnLast: (a: any) => TResult,
784 ...func: Array<(a: any) => any>,
785 f7: (a: R6) => R7,
786 f6: (a: R5) => R6,
787 f5: (a: R4) => R5,
788 f4: (a: R3) => R4,
789 f3: (a: R2) => R3,
790 f2: (a: R1) => R2,
791 f1: (...args: TArgs) => R1,
792 ]
793): (...args: TArgs) => TResult; // fallback overload if number of composed functions greater than 7
794export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
795 f7: (a: R6) => R7,
796 f6: (a: R5) => R6,
797 f5: (a: R4) => R5,
798 f4: (a: R3) => R4,
799 f3: (a: R2) => R3,
800 f2: (a: R1) => R2,
801 f1: (...args: TArgs) => R1,
802): (...args: TArgs) => R7;
803export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
804 f7: (a: R6) => R7,
805 f6: (a: R5) => R6,
806 f5: (a: R4) => R5,
807 f4: (a: R3) => R4,
808 f3: (a: R2) => R3,
809 f2: (a: R1) => R2,
810 f1: (...args: TArgs) => R1,
811): (...args: TArgs) => R7;
812export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
813 f6: (a: R5) => R6,
814 f5: (a: R4) => R5,
815 f4: (a: R3) => R4,
816 f3: (a: R2) => R3,
817 f2: (a: R1) => R2,
818 f1: (...args: TArgs) => R1,
819): (...args: TArgs) => R6;
820export function compose<TArgs extends any[], R1, R2, R3, R4, R5>(
821 f5: (a: R4) => R5,
822 f4: (a: R3) => R4,
823 f3: (a: R2) => R3,
824 f2: (a: R1) => R2,
825 f1: (...args: TArgs) => R1,
826): (...args: TArgs) => R5;
827export function compose<TArgs extends any[], R1, R2, R3, R4>(
828 f4: (a: R3) => R4,
829 f3: (a: R2) => R3,
830 f2: (a: R1) => R2,
831 f1: (...args: TArgs) => R1,
832): (...args: TArgs) => R4;
833export function compose<TArgs extends any[], R1, R2, R3>(
834 f3: (a: R2) => R3,
835 f2: (a: R1) => R2,
836 f1: (...args: TArgs) => R1,
837): (...args: TArgs) => R3;
838export function compose<TArgs extends any[], R1, R2>(
839 f2: (a: R1) => R2,
840 f1: (...args: TArgs) => R1,
841): (...args: TArgs) => R2;
842export function compose<TArgs extends any[], R1>(f1: (...args: TArgs) => R1): (...args: TArgs) => R1;
843
844/**
845 * Performs right-to-left function composition using transforming function.
846 * The last function may have any arity; the remaining functions must be unary.
847 *
848 * @note The result of `R.composeWith` is not automatically curried.
849 * The transforming function is not used on the last argument.
850 *
851 * See also {@link compose}, {@link pipeWith}.
852 *
853 * @example
854 * ```typescript
855 * const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
856 *
857 * composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
858 * ```
859 */
860export function composeWith<TArgs extends any[], TResult>(
861 transformer: (fn: AnyFunction, intermediatResult: any) => any,
862 fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
863): (...args: TArgs) => TResult;
864export function composeWith(
865 transformer: (fn: AnyFunction, intermediatResult: any) => any,
866): <TArgs extends any[], TResult>(
867 fns: AtLeastOneFunctionsFlowFromRightToLeft<TArgs, TResult>,
868) => (...args: TArgs) => TResult;
869
870/**
871 * Returns the result of concatenating the given lists or strings.
872 *
873 * @note `R.concat` expects both arguments to be of the same type,
874 * unlike the native `Array.prototype.concat` method.
875 * It will throw an error if you concat an `Array` with a non-`Array` value.
876 *
877 * Dispatches to the `concat` method of the first argument, if present.
878 * Can also concatenate two members of a fantasy-land compatible semigroup.
879 *
880 * @example
881 * ```typescript
882 * R.concat('ABC', 'DEF'); // 'ABCDEF'
883 * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
884 * R.concat([], []); //=> []
885 * ```
886 */
887export function concat(
888 placeholder: Placeholder,
889): (<L1 extends any[], L2 extends any[]>(list1: L1, list2: L2) => [...L1, ...L2]) &
890 (<S1 extends string, S2 extends string>(s1: S1, s2: S2) => `${S1}${S2}`);
891export function concat<L2 extends any[]>(
892 placeholder: Placeholder,
893 list2: L2,
894): <L1 extends any[]>(list1: L1) => [...L1, ...L2];
895export function concat<S2 extends string>(
896 placeholder: Placeholder,
897 s2: S2,
898): <S1 extends string>(s1: S1) => `${S1}${S2}`;
899export function concat<L1 extends any[]>(list1: L1): <L2 extends any[]>(list2: L2) => [...L1, ...L2];
900export function concat<S1 extends string>(s1: S1): <S2 extends string>(s2: S2) => `${S1}${S2}`;
901export function concat<L1 extends any[], L2 extends any[]>(list1: L1, list2: L2): [...L1, ...L2];
902export function concat<S1 extends string, S2 extends string>(s1: S1, s2: S2): `${S1}${S2}`;
903export function concat(s1: string, s2: string): string;
904export function concat(s1: string): (s2: string) => string;
905
906/**
907 * Returns a function, `fn`, which encapsulates `if/else, if/else, ...` logic.
908 * `R.cond` takes a list of [predicate, transformer] pairs. All of the arguments
909 * to `fn` are applied to each of the predicates in turn until one returns a
910 * "truthy" value, at which point `fn` returns the result of applying its
911 * arguments to the corresponding transformer. If none of the predicates
912 * matches, `fn` returns undefined.
913 *
914 * @note This is not a direct substitute for a `switch` statement.
915 * Remember that both elements of every pair passed to `cond` are *functions*,
916 * and `cond` returns a function.
917 *
918 * @note When using this function with a typeguard as predicate,
919 * **all** predicates in all pairs must be typeguards.
920 *
921 * See also {@link ifElse}, {@link unless}, {@link when}.
922 *
923 * @example
924 * ```typescript
925 * const fn = R.cond([
926 * [R.equals(0), R.always('water freezes at 0°C')],
927 * [R.equals(100), R.always('water boils at 100°C')],
928 * [R.T, temp => 'nothing special happens at ' + temp + '°C']
929 * ]);
930 * fn(0); //=> 'water freezes at 0°C'
931 * fn(50); //=> 'nothing special happens at 50°C'
932 * fn(100); //=> 'water boils at 100°C'
933 * ```
934 */
935export function cond<T, TF1 extends T, R>(pairs: [CondPairTypeguard<T, TF1, R>]): (value: T) => R;
936export function cond<T, TF1 extends T, TF2 extends T, R>(
937 pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>],
938): (value: T) => R;
939export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, R>(
940 pairs: [CondPairTypeguard<T, TF1, R>, CondPairTypeguard<T, TF2, R>, CondPairTypeguard<T, TF3, R>],
941): (value: T) => R;
942export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, R>(
943 pairs: [
944 CondPairTypeguard<T, TF1, R>,
945 CondPairTypeguard<T, TF2, R>,
946 CondPairTypeguard<T, TF3, R>,
947 CondPairTypeguard<T, TF4, R>,
948 ],
949): (value: T) => R;
950export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, R>(
951 pairs: [
952 CondPairTypeguard<T, TF1, R>,
953 CondPairTypeguard<T, TF2, R>,
954 CondPairTypeguard<T, TF3, R>,
955 CondPairTypeguard<T, TF4, R>,
956 CondPairTypeguard<T, TF5, R>,
957 ],
958): (value: T) => R;
959export function cond<T, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T, R>(
960 pairs: [
961 CondPairTypeguard<T, TF1, R>,
962 CondPairTypeguard<T, TF2, R>,
963 CondPairTypeguard<T, TF3, R>,
964 CondPairTypeguard<T, TF4, R>,
965 CondPairTypeguard<T, TF5, R>,
966 CondPairTypeguard<T, TF6, R>,
967 ],
968): (value: T) => R;
969export function cond<
970 T,
971 TF1 extends T,
972 TF2 extends T,
973 TF3 extends T,
974 TF4 extends T,
975 TF5 extends T,
976 TF6 extends T,
977 TF7 extends T,
978 R,
979>(
980 pairs: [
981 CondPairTypeguard<T, TF1, R>,
982 CondPairTypeguard<T, TF2, R>,
983 CondPairTypeguard<T, TF3, R>,
984 CondPairTypeguard<T, TF4, R>,
985 CondPairTypeguard<T, TF5, R>,
986 CondPairTypeguard<T, TF6, R>,
987 CondPairTypeguard<T, TF7, R>,
988 ],
989): (value: T) => R;
990export function cond<
991 T,
992 TF1 extends T,
993 TF2 extends T,
994 TF3 extends T,
995 TF4 extends T,
996 TF5 extends T,
997 TF6 extends T,
998 TF7 extends T,
999 TF8 extends T,
1000 R,
1001>(
1002 pairs: [
1003 CondPairTypeguard<T, TF1, R>,
1004 CondPairTypeguard<T, TF2, R>,
1005 CondPairTypeguard<T, TF3, R>,
1006 CondPairTypeguard<T, TF4, R>,
1007 CondPairTypeguard<T, TF5, R>,
1008 CondPairTypeguard<T, TF6, R>,
1009 CondPairTypeguard<T, TF7, R>,
1010 CondPairTypeguard<T, TF8, R>,
1011 ],
1012): (value: T) => R;
1013export function cond<
1014 T,
1015 TF1 extends T,
1016 TF2 extends T,
1017 TF3 extends T,
1018 TF4 extends T,
1019 TF5 extends T,
1020 TF6 extends T,
1021 TF7 extends T,
1022 TF8 extends T,
1023 TF9 extends T,
1024 R,
1025>(
1026 pairs: [
1027 CondPairTypeguard<T, TF1, R>,
1028 CondPairTypeguard<T, TF2, R>,
1029 CondPairTypeguard<T, TF3, R>,
1030 CondPairTypeguard<T, TF4, R>,
1031 CondPairTypeguard<T, TF5, R>,
1032 CondPairTypeguard<T, TF6, R>,
1033 CondPairTypeguard<T, TF7, R>,
1034 CondPairTypeguard<T, TF8, R>,
1035 CondPairTypeguard<T, TF9, R>,
1036 ],
1037): (value: T) => R;
1038export function cond<
1039 T,
1040 TF1 extends T,
1041 TF2 extends T,
1042 TF3 extends T,
1043 TF4 extends T,
1044 TF5 extends T,
1045 TF6 extends T,
1046 TF7 extends T,
1047 TF8 extends T,
1048 TF9 extends T,
1049 TF10 extends T,
1050 R,
1051>(
1052 pairs: [
1053 CondPairTypeguard<T, TF1, R>,
1054 CondPairTypeguard<T, TF2, R>,
1055 CondPairTypeguard<T, TF3, R>,
1056 CondPairTypeguard<T, TF4, R>,
1057 CondPairTypeguard<T, TF5, R>,
1058 CondPairTypeguard<T, TF6, R>,
1059 CondPairTypeguard<T, TF7, R>,
1060 CondPairTypeguard<T, TF8, R>,
1061 CondPairTypeguard<T, TF9, R>,
1062 CondPairTypeguard<T, TF10, R>,
1063 ],
1064): (value: T) => R;
1065export function cond<T extends any[], R>(pairs: ReadonlyArray<CondPair<T, R>>): (...args: T) => R;
1066
1067/**
1068 * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
1069 *
1070 * See also {@link invoker}.
1071 *
1072 * @example
1073 * ```typescript
1074 * // Constructor function
1075 * class Animal {
1076 * constructor(public kind: string) {}
1077 *
1078 * sighting() {
1079 * return "It's a " + this.kind + "!";
1080 * }
1081 * }
1082 *
1083 * const AnimalConstructor = R.construct(Animal)
1084 *
1085 * // Notice we no longer need the 'new' keyword:
1086 * AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}};
1087 *
1088 * const animalTypes = ["Lion", "Tiger", "Bear"];
1089 * const animalSighting = R.invoker(0, 'sighting');
1090 * const sightNewAnimal = R.compose(animalSighting, AnimalConstructor);
1091 * R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"]
1092 * ```
1093 */
1094export function construct<A extends any[], T>(
1095 constructor: { new (...args: A): T } | ((...args: A) => T),
1096): _.F.Curry<(...args: A) => T>;
1097
1098// NOTE: Example doesn't work with this typing
1099/**
1100 * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
1101 * The arity of the function returned is specified to allow using variadic constructor functions.
1102 */
1103export function constructN<A extends any[], T, N extends number>(
1104 n: N,
1105 constructor: { new (...args: A): T } | ((...args: A) => T),
1106): _.F.Curry<(...args: mergeArrWithLeft<Tuple<any, N>, A>) => T>;
1107
1108// NOTE: Example doesn't work with this typing
1109/**
1110 * Accepts a converging function and a list of branching functions and returns a new function.
1111 * When invoked, this new function is applied to some arguments,
1112 * each branching function is applied to those same arguments.
1113 * The results of each branching function are passed as arguments to the converging function
1114 * to produce the return value.
1115 *
1116 * See also {@link useWith}.
1117 */
1118export function converge<
1119 TResult,
1120 FunctionsList extends ReadonlyArray<Fn> &
1121 IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
1122 _Fns extends ReadonlyArray<Fn> = FunctionsList,
1123>(
1124 converging: (...args: ReturnTypesOfFns<FunctionsList>) => TResult,
1125 branches: FunctionsList,
1126): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
1127export function converge<
1128 CArgs extends ReadonlyArray<any>,
1129 TResult,
1130 FunctionsList extends readonly [
1131 ...{
1132 [Index in keyof CArgs]: (...args: ReadonlyArray<any>) => CArgs[Index];
1133 },
1134 ] &
1135 IfFunctionsArgumentsDoNotOverlap<_Fns, 'Functions arguments types must overlap'>,
1136 _Fns extends ReadonlyArray<Fn> = FunctionsList,
1137>(
1138 converging: (...args: CArgs) => TResult,
1139 branches: FunctionsList,
1140): _.F.Curry<(...args: LargestArgumentsList<FunctionsList>) => TResult>;
1141
1142/**
1143 * Returns the number of items in a given `list` matching the predicate `f`.
1144 *
1145 * @example
1146 * ```typescript
1147 * const even = (x: number) => x % 2 == 0;
1148 *
1149 * R.count(even, [1, 2, 3, 4, 5]); // => 2
1150 * R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
1151 * ```
1152 */
1153export function count<T>(fn: (a: T) => boolean, list: readonly T[]): number;
1154export function count<T>(fn: (a: T) => boolean): (list: readonly T[]) => number;
1155
1156/**
1157 * Counts the elements of a list according to how many match each value of a key generated by the supplied function.
1158 * Returns an object mapping the keys produced by `fn` to the number of occurrences in the list.
1159 * Note that all keys are coerced to strings because of how JavaScript objects work.
1160 *
1161 * Acts as a transducer if a transformer is given in list position.
1162 *
1163 * See also {@link transduce}.
1164 *
1165 * @example
1166 * ```typescript
1167 * const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
1168 * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
1169 *
1170 * const letters = ['a', 'b', 'A', 'a', 'B', 'c'];
1171 * R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1}
1172 * ```
1173 */
1174export function countBy<T>(fn: (a: T) => string | number, list: readonly T[]): { [index: string]: number };
1175export function countBy<T>(fn: (a: T) => string | number): (list: readonly T[]) => { [index: string]: number };
1176
1177/**
1178 * Returns a curried equivalent of the provided function.
1179 *
1180 * See also {@link curryN}, {@link partial}.
1181 *
1182 * The curried function has two unusual capabilities.
1183 *
1184 * First, its arguments needn't be provided one at a time.
1185 * If `f` is a ternary function and `g` is `R.curry(f)`, the following are equivalent:
1186 * - `g(1)(2)(3)`
1187 * - `g(1)(2, 3)`
1188 * - `g(1, 2)(3)`
1189 * - `g(1, 2, 3)`
1190 *
1191 * Secondly, the special placeholder value `R.__` may be used to specify "gaps",
1192 * allowing partial application of any combination of arguments,
1193 * regardless of their positions.
1194 * If `g` is as above and `_` is `R.__`, the following are equivalent:
1195 * - `g(1, 2, 3)`
1196 * - `g(_, 2, 3)(1)`
1197 * - `g(_, _, 3)(1)(2)`
1198 * - `g(_, _, 3)(1, 2)`
1199 * - `g(_, 2)(1)(3)`
1200 * - `g(_, 2)(1, 3)`
1201 * - `g(_, 2)(_, 3)(1)`
1202 *
1203 * @example
1204 * ```typescript
1205 * const addFourNumbers = (a: number, b: number, c: number, d: number) => a + b + c + d;
1206 *
1207 * const curriedAddFourNumbers = R.curry(addFourNumbers);
1208 * const f = curriedAddFourNumbers(1, 2);
1209 * const g = f(3);
1210 * g(4); //=> 10
1211 * ```
1212 */
1213export function curry<F extends AnyFunction>(f: F): _.F.Curry<F>;
1214
1215/**
1216 * Returns a curried equivalent of the provided function, with the specified arity.
1217 *
1218 * See also {@link curry}.
1219 *
1220 * The curried function has two unusual capabilities.
1221 *
1222 * First, its arguments needn't be provided one at a time.
1223 * If `f` is a ternary function and `g` is `R.curry(f)`, the following are equivalent:
1224 * - `g(1)(2)(3)`
1225 * - `g(1)(2, 3)`
1226 * - `g(1, 2)(3)`
1227 * - `g(1, 2, 3)`
1228 *
1229 * Secondly, the special placeholder value `R.__` may be used to specify "gaps",
1230 * allowing partial application of any combination of arguments,
1231 * regardless of their positions.
1232 * If `g` is as above and `_` is `R.__`, the following are equivalent:
1233 * - `g(1, 2, 3)`
1234 * - `g(_, 2, 3)(1)`
1235 * - `g(_, _, 3)(1)(2)`
1236 * - `g(_, _, 3)(1, 2)`
1237 * - `g(_, 2)(1)(3)`
1238 * - `g(_, 2)(1, 3)`
1239 * - `g(_, 2)(_, 3)(1)`
1240 *
1241 * @example
1242 * ```typescript
1243 * const sumArgs = (...args: number[]) => R.sum(args);
1244 *
1245 * const curriedAddFourNumbers = R.curryN(4, sumArgs);
1246 * const f = curriedAddFourNumbers(1, 2);
1247 * const g = f(3);
1248 * g(4); //=> 10
1249 * ```
1250 */
1251export function curryN<N extends number, F extends AnyFunction>(
1252 length: N,
1253 fn: F,
1254): _.F.Curry<(...args: _.T.Take<Parameters<F>, _.N.NumberOf<N>>) => ReturnType<F>>;
1255export function curryN<N extends number>(
1256 length: N,
1257): <F extends AnyFunction>(fn: F) => _.F.Curry<(...args: _.T.Take<Parameters<F>, _.N.NumberOf<N>>) => ReturnType<F>>;
1258
1259/**
1260 * Decrements its argument.
1261 *
1262 * See also {@link inc}.
1263 *
1264 * @example
1265 * ```typescript
1266 * R.dec(42); //=> 41
1267 * ```
1268 */
1269export function dec(n: number): number;
1270
1271/**
1272 * Returns the second argument if it is not `null`, `undefined` or `NaN`; otherwise the first argument is returned.
1273 *
1274 * @example
1275 * ```typescript
1276 * const defaultTo42 = R.defaultTo(42);
1277 *
1278 * defaultTo42(null); //=> 42
1279 * defaultTo42(undefined); //=> 42
1280 * defaultTo42(false); //=> false
1281 * defaultTo42('Ramda'); //=> 'Ramda'
1282 * // parseInt('string') results in NaN
1283 * defaultTo42(parseInt('string')); //=> 42
1284 * ```
1285 */
1286export function defaultTo<T, U>(a: T, b: U | null | undefined): T | U;
1287export function defaultTo<T>(a: T): <U>(b: U | null | undefined) => T | U;
1288
1289/**
1290 * Makes a descending comparator function out of a function that returns a value that can be compared with `<` and `>`.
1291 *
1292 * See also {@link ascend}.
1293 *
1294 * @example
1295 * ```typescript
1296 * type Person = { name: string; age: number; };
1297 *
1298 * const byAge = R.descend<Person>(R.prop('age'));
1299 * const people = [
1300 * { name: 'Emma', age: 70 },
1301 * { name: 'Peter', age: 78 },
1302 * { name: 'Mikhail', age: 62 },
1303 * ];
1304 * const peopleByOldestFirst = R.sort(byAge, people);
1305 * //=> [{ name: 'Peter', age: 78 }, { name: 'Emma', age: 70 }, { name: 'Mikhail', age: 62 }]
1306 * ```
1307 */
1308export function descend<T>(fn: (obj: T) => Ord, a: T, b: T): Ordering;
1309export function descend<T>(fn: (obj: T) => Ord): (a: T, b: T) => Ordering;
1310
1311/**
1312 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
1313 * `Object`s and `Array`s are compared in terms of value equality, not reference equality.
1314 *
1315 * See also {@link differenceWith}, {@link symmetricDifference}, {@link symmetricDifferenceWith}, {@link without}.
1316 *
1317 * @example
1318 * ```typescript
1319 * R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
1320 * R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]
1321 * R.difference<{ a: number; } | { b: number; } | { c: number; }>([{a: 1}, {b: 2}], [{a: 1}, {c: 3}]) //=> [{b: 2}]
1322 * ```
1323 */
1324export function difference<T>(list1: readonly T[], list2: readonly T[]): T[];
1325export function difference<T>(list1: readonly T[]): (list2: readonly T[]) => T[];
1326
1327/**
1328 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
1329 * Duplication is determined according to the value returned
1330 * by applying the supplied predicate to two list elements.
1331 *
1332 * See also See also {@link difference}, {@link symmetricDifference}, {@link symmetricDifferenceWith}.
1333 *
1334 * @example
1335 * ```typescript
1336 * const cmp = (x: { a: number; }, y: { a: number; }) => x.a === y.a;
1337 * const l1 = [{a: 1}, {a: 2}, {a: 3}];
1338 * const l2 = [{a: 3}, {a: 4}];
1339 * R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}]
1340 * ```
1341 */
1342export function differenceWith<T1, T2>(
1343 pred: (a: T1, b: T2) => boolean,
1344 list1: readonly T1[],
1345 list2: readonly T2[],
1346): T1[];
1347export function differenceWith<T1, T2>(
1348 pred: (a: T1, b: T2) => boolean,
1349): (list1: readonly T1[], list2: readonly T2[]) => T1[];
1350export function differenceWith<T1, T2>(
1351 pred: (a: T1, b: T2) => boolean,
1352 list1: readonly T1[],
1353): (list2: readonly T2[]) => T1[];
1354
1355/**
1356 * Returns a new object that does not contain the given property.
1357 *
1358 * See also {@link assoc}, {@link omit}.
1359 *
1360 * @example
1361 * ```typescript
1362 * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3}
1363 * ```
1364 */
1365export function dissoc<T extends object, K extends keyof T>(prop: K, obj: T): Omit<T, K>;
1366export function dissoc<K extends string | number>(prop: K): <T extends object>(obj: T) => Omit<T, K>;
1367
1368/**
1369 * Makes a shallow clone of an object, omitting the property at the given path.
1370 *
1371 * @note This copies and flattens prototype properties onto the new object as well.
1372 * All non-primitive properties are copied by reference.
1373 *
1374 * @example
1375 * ```typescript
1376 * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}}
1377 * ```
1378 */
1379export function dissocPath<T>(path: Path, obj: any): T;
1380export function dissocPath<T>(path: Path): (obj: any) => T;
1381
1382/**
1383 * Divides two numbers. Equivalent to `a / b` but curried.
1384 *
1385 * See also {@link multiply}.
1386 *
1387 * @example
1388 * ```typescript
1389 * R.divide(71, 100); //=> 0.71
1390 *
1391 * const half = R.divide(R.__, 2);
1392 * half(42); //=> 21
1393 *
1394 * const reciprocal = R.divide(1);
1395 * reciprocal(4); //=> 0.25
1396 * ```
1397 */
1398export function divide(__: Placeholder, b: number): (a: number) => number;
1399export function divide(__: Placeholder): (b: number, a: number) => number;
1400export function divide(a: number, b: number): number;
1401export function divide(a: number): (b: number) => number;
1402
1403/**
1404 * Returns all but the first `n` elements of the given list, string, or transducer/transformer.
1405 *
1406 * Dispatches to the `drop` method of the second argument, if present.
1407 *
1408 * See also {@link take}, {@link transduce}, {@link dropLast}, {@link dropWhile}.
1409 *
1410 * @example
1411 * ```typescript
1412 * R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
1413 * R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz']
1414 * R.drop(3, ['foo', 'bar', 'baz']); //=> []
1415 * R.drop(4, ['foo', 'bar', 'baz']); //=> []
1416 * R.drop(3, 'ramda'); //=> 'da'
1417 * ```
1418 */
1419export function drop<T>(n: number, xs: readonly T[]): T[];
1420export function drop(n: number, xs: string): string;
1421export function drop<T>(n: number): {
1422 (xs: string): string;
1423 (xs: readonly T[]): T[];
1424};
1425
1426/**
1427 * Returns a list containing all but the last `n` elements of the given list.
1428 *
1429 * Acts as a transducer if a transformer is given in list position.
1430 *
1431 * See also {@link takeLast}, {@link drop}, {@link dropWhile}, {@link dropLastWhile}, {@link transduce}.
1432 *
1433 * @example
1434 * ```typescript
1435 * R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
1436 * R.dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo']
1437 * R.dropLast(3, ['foo', 'bar', 'baz']); //=> []
1438 * R.dropLast(4, ['foo', 'bar', 'baz']); //=> []
1439 * R.dropLast(3, 'ramda'); //=> 'ra'
1440 * ```
1441 */
1442export function dropLast<T>(n: number, xs: readonly T[]): T[];
1443export function dropLast(n: number, xs: string): string;
1444export function dropLast<T>(n: number): {
1445 (xs: readonly T[]): T[];
1446 (xs: string): string;
1447};
1448
1449/**
1450 * Returns a new list excluding all the tailing elements of a given list which satisfy the supplied predicate function.
1451 * It passes each value from the right to the supplied predicate function,
1452 * skipping elements until the predicate function returns a falsy value.
1453 *
1454 * Acts as a transducer if a transformer is given in list position.
1455 *
1456 * See also {@link takeLastWhile}, {@link addIndex}, {@link drop}, {@link dropWhile}, {@link transduce}.
1457 *
1458 * @example
1459 * ```typescript
1460 * const lteThree = (x: number) => x <= 3;
1461 *
1462 * R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3, 4]
1463 *
1464 * R.dropLastWhile(x => x !== 'd', 'Ramda'); //=> 'Ramd'
1465 * ```
1466 */
1467export function dropLastWhile<T>(fn: (a: T) => boolean, list: readonly T[]): T[];
1468export function dropLastWhile<T>(fn: (a: T) => boolean): (list: readonly T[]) => T[];
1469
1470/**
1471 * Returns a new list without any consecutively repeating elements.
1472 * {@link equals `R.equals`} is used to determine equality.
1473 *
1474 * Acts as a transducer if a transformer is given in list position.
1475 *
1476 * See also {@link transduce}.
1477 *
1478 * @example
1479 * ```typescript
1480 * R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2]
1481 * ```
1482 */
1483export function dropRepeats<T>(list: readonly T[]): T[];
1484
1485/**
1486 * Returns a new list without any consecutively repeating elements.
1487 * Equality is determined by applying the supplied predicate to each pair of consecutive elements.
1488 * The first element in a series of equal elements will be preserved.
1489 *
1490 * Acts as a transducer if a transformer is given in list position.
1491 *
1492 * See also {@link transduce}.
1493 *
1494 * @example
1495 * ```typescript
1496 * const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
1497 * R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
1498 * ```
1499 */
1500export function dropRepeatsWith<T>(predicate: (left: T, right: T) => boolean, list: readonly T[]): T[];
1501export function dropRepeatsWith<T>(predicate: (left: T, right: T) => boolean): (list: readonly T[]) => T[];
1502
1503/**
1504 * Returns a new list excluding the leading elements of a given list
1505 * which satisfy the supplied predicate function.
1506 * It passes each value to the supplied predicate function,
1507 * skipping elements while the predicate function returns a truthy value.
1508 *
1509 * Dispatches to the `dropWhile` method of the second argument, if present.
1510 *
1511 * Acts as a transducer if a transformer is given in list position.
1512 *
1513 * See also {@link takeWhile}, {@link addIndex}, {@link transduce}.
1514 *
1515 * @example
1516 * ```typescript
1517 * const lteTwo = (x: number) => x <= 2;
1518 *
1519 * R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1]
1520 *
1521 * R.dropWhile(x => x !== 'd' , 'Ramda'); //=> 'da'
1522 * ```
1523 */
1524export function dropWhile<T>(fn: (a: T) => boolean, list: readonly T[]): T[];
1525export function dropWhile<T>(fn: (a: T) => boolean): (list: readonly T[]) => T[];
1526
1527/**
1528 * A function wrapping calls to the two functions in an `||` operation,
1529 * returning the result of the first function if it is truthy
1530 * and the result of the second function otherwise.
1531 *
1532 * @note This is short-circuited, meaning that the second function will not be invoked if the first returns a truthy value.
1533 *
1534 * See also {@link both}, {@link or}.
1535 *
1536 * @example
1537 * ```typescript
1538 * const gt10 = (x: number) => x > 10;
1539 * const even = (x: number) => x % 2 === 0;
1540 * const f = R.either(gt10, even);
1541 * f(101); //=> true
1542 * f(8); //=> true
1543 * ```
1544 */
1545export function either<T extends Pred>(pred1: T, pred2: T): T;
1546export function either<T extends Pred>(pred1: T): (pred2: T) => T;
1547
1548/**
1549 * Returns the empty value of its argument's type.
1550 * Ramda defines the empty value of `Array` (`[]`), `Object` (`{}`), string (`''`),
1551 * `TypedArray` (`Uint8Array []`, `Float32Array []`, etc) and arguments.
1552 *
1553 * Other types are supported if they define `<Type>.empty`, `<Type>.prototype.empty`
1554 * or implement the FantasyLand Monoid spec.
1555 *
1556 * Dispatches to the `empty` method of the first argument, if present.
1557 *
1558 * @example
1559 * ```typescript
1560 * R.empty([1, 2, 3]); //=> []
1561 * R.empty('unicorns'); //=> ''
1562 * R.empty({x: 1, y: 2}); //=> {}
1563 * R.empty(Uint8Array.from([1, 2, 3])); //=> Uint8Array []
1564 * ```
1565 */
1566export function empty<T>(x: T): T;
1567
1568/**
1569 * Checks if a list ends with the provided sublist.
1570 *
1571 * Similarly, checks if a string ends with the provided substring.
1572 *
1573 * See also {@link startsWith}.
1574 *
1575 * @example
1576 * ```typescript
1577 * R.endsWith('c', 'abc') //=> true
1578 * R.endsWith('b', 'abc') //=> false
1579 * R.endsWith(['c'], ['a', 'b', 'c']) //=> true
1580 * R.endsWith(['b'], ['a', 'b', 'c']) //=> false
1581 * ```
1582 */
1583export function endsWith(substr: string, str: string): boolean;
1584export function endsWith(substr: string): (str: string) => boolean;
1585export function endsWith<T>(subList: readonly T[], list: readonly T[]): boolean;
1586export function endsWith<T>(subList: readonly T[]): (list: readonly T[]) => boolean;
1587
1588/**
1589 * Takes a function and two values in its domain and returns `true` if the values map to the same value in the codomain;
1590 * `false` otherwise.
1591 *
1592 * @example
1593 * ```typescript
1594 * R.eqBy(Math.abs, 5, -5); //=> true
1595 * ```
1596 */
1597export function eqBy<T>(fn: (a: T) => unknown, a: T, b: T): boolean;
1598export function eqBy<T>(fn: (a: T) => unknown, a: T): (b: T) => boolean;
1599export function eqBy<T>(fn: (a: T) => unknown): {
1600 (a: T, b: T): boolean;
1601 (a: T): (b: T) => boolean;
1602};
1603
1604/**
1605 * Reports whether two objects have the same value, in {@link equals `R.equals`} terms, for the specified property.
1606 * Useful as a curried predicate.
1607 *
1608 * @example
1609 * ```typescript
1610 * const o1 = { a: 1, b: 2, c: 3, d: 4 };
1611 * const o2 = { a: 10, b: 20, c: 3, d: 40 };
1612 * R.eqProps('a', o1, o2); //=> false
1613 * R.eqProps('c', o1, o2); //=> true
1614 * ```
1615 */
1616export function eqProps<T, U>(prop: string, obj1: T, obj2: U): boolean;
1617export function eqProps<P extends string>(prop: P): <T, U>(obj1: Record<P, T>, obj2: Record<P, U>) => boolean;
1618export function eqProps<T>(prop: string, obj1: T): <U>(obj2: U) => boolean;
1619
1620/**
1621 * Returns `true` if its arguments are equivalent, `false` otherwise.
1622 * Handles cyclical data structures.
1623 *
1624 * Dispatches symmetrically to the `equals` methods of both arguments, if present.
1625 *
1626 * @example
1627 * ```typescript
1628 * R.equals(1, 1); //=> true
1629 * R.equals([1, 2, 3], [1, 2, 3]); //=> true
1630 *
1631 * type Recursive = { v: Recursive; };
1632 *
1633 * const a: Recursive = {} as Recursive; a.v = a;
1634 * const b: Recursive = {} as Recursive; b.v = b;
1635 * R.equals(a, b); //=> true
1636 * ```
1637 */
1638export function equals<T>(__: Placeholder, b: T): (a: T) => boolean;
1639export function equals<T>(a: T, b: T): boolean;
1640export function equals<T>(a: T): (b: T) => boolean;
1641
1642/**
1643 * Creates a new object by evolving a shallow copy of the `object`,
1644 * according to the functions in `transformations`.
1645 * All non-primitive properties are copied by reference.
1646 *
1647 * A function in `transformations` will not be invoked if its corresponding key does not exist in the evolved object.
1648 *
1649 * @example
1650 * ```typescript
1651 * const tomato = {firstName: ' Tomato ', data: {elapsed: 100, remaining: 1400}, id:123};
1652 * const transformations = {
1653 * firstName: R.trim,
1654 * lastName: R.trim, // Will not get invoked.
1655 * data: {elapsed: R.add(1), remaining: R.add(-1)}
1656 * };
1657 * R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123}
1658 * ```
1659 */
1660export function evolve<E extends Evolver, V extends Evolvable<E>>(transformations: E, obj: V): Evolve<V, E>;
1661export function evolve<E extends Evolver>(transformations: E): <V extends Evolvable<E>>(obj: V) => Evolve<V, E>;
1662
1663/**
1664 * A function that always returns `false`.
1665 * Any passed in parameters are ignored.
1666 *
1667 * See also {@link T}.
1668 *
1669 * @example
1670 * ```typescript
1671 * R.F(); //=> false
1672 * ```
1673 */
1674export function F(...args: unknown[]): false;
1675
1676/**
1677 * Takes a predicate and a `Filterable`,
1678 * and returns a new `Filterable` of the same type
1679 * containing the members of the given `Filterable` which satisfy the given predicate.
1680 * Filterable objects include plain objects or any object that has a filter method such as Array.
1681 *
1682 * Dispatches to the `filter` method of the second argument, if present.
1683 *
1684 * Acts as a transducer if a transformer is given in list position.
1685 *
1686 * See also {@link reject}, {@link transduce}, {@link addIndex}.
1687 *
1688 * @example
1689 * ```typescript
1690 * const isEven = (n: number) => n % 2 === 0;
1691 *
1692 * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
1693 *
1694 * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}
1695 * ```
1696 */
1697export function filter<A, P extends A>(
1698 pred: (val: A) => val is P,
1699): {
1700 <B extends A>(list: readonly B[]): P[];
1701 <B extends A>(dict: Dictionary<B>): Dictionary<P>;
1702};
1703export function filter<T>(
1704 pred: (value: T) => boolean,
1705): <P extends T, C extends readonly P[] | Dictionary<P>>(collection: C) => C;
1706export function filter<T, P extends T>(pred: (val: T) => val is P, list: readonly T[]): P[];
1707export function filter<T, P extends T>(pred: (val: T) => val is P, dict: Dictionary<T>): Dictionary<P>;
1708export function filter<T, C extends readonly T[] | Dictionary<T>>(pred: (value: T) => boolean, collection: C): C;
1709
1710/**
1711 * Returns the first element of the list which matches the predicate,
1712 * or `undefined` if no element matches.
1713 *
1714 * Dispatches to the `find` method of the second argument, if present.
1715 *
1716 * Acts as a transducer if a transformer is given in list position.
1717 *
1718 * See also {@link transduce}.
1719 *
1720 * @example
1721 * ```typescript
1722 * const xs = [{a: 1}, {a: 2}, {a: 3}];
1723 * R.find(R.propEq('a', 2))(xs); //=> {a: 2}
1724 * R.find(R.propEq('a', 4))(xs); //=> undefined
1725 * ```
1726 */
1727export function find<T, P extends T>(pred: (val: T) => val is P, list: readonly T[]): P | undefined;
1728export function find<T>(pred: (val: T) => boolean, list: readonly T[]): T | undefined;
1729export function find<T, P extends T>(pred: (val: T) => val is P): (list: readonly T[]) => P | undefined;
1730export function find<T>(pred: (val: T) => boolean): (list: readonly T[]) => T | undefined;
1731
1732/**
1733 * Returns the index of the first element of the list which matches the predicate,
1734 * or `-1` if no element matches.
1735 *
1736 * Acts as a transducer if a transformer is given in list position.
1737 *
1738 * See also {@link indexOf}, {@link transduce}.
1739 *
1740 * @example
1741 * ```typescript
1742 * const xs = [{a: 1}, {a: 2}, {a: 3}];
1743 * R.findIndex(R.propEq('a', 2))(xs); //=> 1
1744 * R.findIndex(R.propEq('a', 4))(xs); //=> -1
1745 * ```
1746 */
1747export function findIndex<T>(fn: (a: T) => boolean, list: readonly T[]): number;
1748export function findIndex<T>(fn: (a: T) => boolean): (list: readonly T[]) => number;
1749
1750/**
1751 * Returns the last element of the list which matches the predicate, or `undefined` if no element matches.
1752 *
1753 * Acts as a transducer if a transformer is given in list position.
1754 *
1755 * See also {@link transduce}.
1756 *
1757 * @example
1758 * ```typescript
1759 * const xs = [{a: 1, b: 0}, {a:1, b: 1}];
1760 * R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1}
1761 * R.findLast(R.propEq('a', 4))(xs); //=> undefined
1762 * ```
1763 */
1764export function findLast<T, P extends T>(pred: (val: T) => val is P, list: readonly T[]): P | undefined;
1765export function findLast<T>(pred: (val: T) => boolean, list: readonly T[]): T | undefined;
1766export function findLast<T, P extends T>(pred: (val: T) => val is P): (list: readonly T[]) => P | undefined;
1767export function findLast<T>(pred: (val: T) => boolean): (list: readonly T[]) => T | undefined;
1768
1769/**
1770 * Returns the index of the last element of the list which matches the predicate,
1771 * or `-1` if no element matches.
1772 *
1773 * Acts as a transducer if a transformer is given in list position.
1774 *
1775 * See also {@link lastIndexOf}, {@link transduce}.
1776 *
1777 * @example
1778 * ```typescript
1779 * const xs = [{a: 1, b: 0}, {a:1, b: 1}];
1780 * R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
1781 * R.findLastIndex(R.propEq('a', 4))(xs); //=> -1
1782 * ```
1783 */
1784export function findLastIndex<T>(fn: (a: T) => boolean, list: readonly T[]): number;
1785export function findLastIndex<T>(fn: (a: T) => boolean): (list: readonly T[]) => number;
1786
1787/**
1788 * Returns a new list by pulling every item out of it (and all its sub-arrays)
1789 * and putting them in a new array, depth-first.
1790 *
1791 * See also {@link unnest}.
1792 *
1793 * @example
1794 * ```typescript
1795 * R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
1796 * //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
1797 * ```
1798 */
1799export function flatten<T extends readonly any[]>(list: T): _.T.Flatten<T>;
1800
1801/**
1802 * Flips the order of the first two arguments to the given function.
1803 *
1804 * @example
1805 * ```typescript
1806 * const mergeThree = <T>(a: T, b: T, c: T) => ([] as T[]).concat(a, b, c);
1807 *
1808 * mergeThree(1, 2, 3); //=> [1, 2, 3]
1809 *
1810 * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]
1811 * ```
1812 */
1813export function flip<T, U, TResult>(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult;
1814export function flip<F extends AnyFunction, P extends _.F.Parameters<F>>(
1815 fn: F,
1816): _.F.Curry<(...args: _.T.Merge<[P[1], P[0]], P>) => _.F.Return<F>>;
1817
1818/**
1819 * Iterate over the given list, calling the given function for each element in the list.
1820 *
1821 * @note `R.forEach` does not skip deleted or unassigned indices (sparse arrays),
1822 * unlike the native `Array.prototype.forEach` method.
1823 *
1824 * Also note that, unlike `Array.prototype.forEach`, `R.forEach` returns the original array.
1825 * In some libraries this function is named `each`.
1826 *
1827 * Dispatches to the `forEach` method of the second argument, if present.
1828 *
1829 * @example
1830 * ```typescript
1831 * const printXPlusFive = (x: number) => console.log(x + 5);
1832 * R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
1833 * // logs 6
1834 * // logs 7
1835 * // logs 8
1836 * ```
1837 */
1838export function forEach<T>(fn: (x: T) => void, list: readonly T[]): T[];
1839export function forEach<T>(fn: (x: T) => void): (list: readonly T[]) => T[];
1840export function forEach<T>(fn: (x: T) => void, list: readonly T[]): T[];
1841export function forEach<T>(fn: (x: T) => void): (list: readonly T[]) => T[];
1842
1843/**
1844 * Iterate over the given object, calling the given function for each key and value in the object.
1845 *
1846 * @example
1847 * ```typescript
1848 * const printKeyConcatValue = (value: unknown, key: string) => console.log(key + ':' + value);
1849 * R.forEachObjIndexed(printKeyConcatValue, {x: 1, y: 2}); //=> {x: 1, y: 2}
1850 * // logs x:1
1851 * // logs y:2
1852 * ```
1853 */
1854export function forEachObjIndexed<T>(fn: (value: T[keyof T], key: keyof T, obj: T) => void, obj: T): T;
1855export function forEachObjIndexed<T>(fn: (value: T[keyof T], key: keyof T, obj: T) => void): (obj: T) => T;
1856
1857/**
1858 * Creates a new object from a list key-value pairs.
1859 * If a key appears in multiple pairs,
1860 * the rightmost pair is included in the object.
1861 *
1862 * See also {@link toPairs}, {@link pair}.
1863 *
1864 * @example
1865 * ```typescript
1866 * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}
1867 * ```
1868 */
1869export function fromPairs<V>(
1870 pairs: ReadonlyArray<Readonly<KeyValuePair<string, V>>> | ReadonlyArray<Readonly<KeyValuePair<number, V>>>,
1871): { [index: string]: V };
1872
1873/**
1874 * Splits a list into sub-lists stored in an object,
1875 * based on the result of calling a key-returning function on each element,
1876 * and grouping the results according to values returned.
1877 *
1878 * Dispatches to the `groupBy` method of the second argument, if present.
1879 *
1880 * Acts as a transducer if a transformer is given in list position.
1881 *
1882 * See also {@link reduceBy}, {@link indexBy}, {@link transduce}.
1883 *
1884 * @example
1885 * ```typescript
1886 * type Student = { name: string; score: number; }
1887 *
1888 * const byGrade = R.groupBy((student: Student) => {
1889 * const score = student.score;
1890 * return score < 65 ? 'F' :
1891 * score < 70 ? 'D' :
1892 * score < 80 ? 'C' :
1893 * score < 90 ? 'B' : 'A';
1894 * });
1895 * const students = [{name: 'Abby', score: 84},
1896 * {name: 'Eddy', score: 58},
1897 * // ...
1898 * {name: 'Jack', score: 69}];
1899 * byGrade(students);
1900 * // {
1901 * // 'A': [{name: 'Dianne', score: 99}],
1902 * // 'B': [{name: 'Abby', score: 84}]
1903 * // // ...,
1904 * // 'F': [{name: 'Eddy', score: 58}]
1905 * // }
1906 * ```
1907 */
1908export function groupBy<T, K extends string = string>(fn: (a: T) => K, list: readonly T[]): Record<K, T[]>;
1909export function groupBy<T, K extends string = string>(fn: (a: T) => K): (list: readonly T[]) => Record<K, T[]>;
1910
1911/**
1912 * Takes a list and returns a list of lists
1913 * where every adjacent element of each sublist satisfies the given predicate.
1914 *
1915 * @example
1916 * ```typescript
1917 * R.groupWith(R.equals, [0, 1, 1, 2, 3, 5, 8, 13, 21])
1918 * //=> [[0], [1, 1], [2], [3], [5], [8], [13], [21]]
1919 *
1920 * R.groupWith((a, b) => a + 1 === b, [0, 1, 1, 2, 3, 5, 8, 13, 21])
1921 * //=> [[0, 1], [1, 2, 3], [5], [8], [13], [21]]
1922 *
1923 * R.groupWith((a, b) => a % 2 === b % 2, [0, 1, 1, 2, 3, 5, 8, 13, 21])
1924 * //=> [[0], [1, 1], [2], [3, 5], [8], [13, 21]]
1925 *
1926 * const isVowel = R.test(/^[aeiou]$/i);
1927 * R.groupWith(R.eqBy(isVowel), 'aestiou')
1928 * //=> ['ae', 'st', 'iou']
1929 * ```
1930 */
1931export function groupWith<T>(fn: (x: T, y: T) => boolean): (list: readonly T[]) => T[][];
1932export function groupWith<T>(fn: (x: T, y: T) => boolean, list: readonly T[]): T[][];
1933export function groupWith<T>(fn: (x: T, y: T) => boolean, list: string): string[];
1934
1935/**
1936 * Returns `true` if the first parameter is greater than the second; `false` otherwise.
1937 *
1938 * See also {@link gte}, {@link lt}, {@link lte}.
1939 *
1940 * @example
1941 * ```typescript
1942 * R.gt(2, 1); //=> true
1943 * R.gt(2, 2); //=> false
1944 * R.gt(2, 3); //=> false
1945 * R.gt('a', 'z'); //=> false
1946 * R.gt('z', 'a'); //=> true
1947 * ```
1948 */
1949export function gt(__: Placeholder, b: number): (a: number) => boolean;
1950export function gt(__: Placeholder): (b: number, a: number) => boolean;
1951export function gt(a: number, b: number): boolean;
1952export function gt(a: string, b: string): boolean;
1953export function gt(a: number): (b: number) => boolean;
1954
1955/**
1956 * Returns `true` if the first parameter is greater than or equal to the second; `false` otherwise.
1957 *
1958 * See also {@link gt}, {@link lt}, {@link lte}.
1959 *
1960 * @example
1961 * ```typescript
1962 * R.gte(2, 1); //=> true
1963 * R.gte(2, 2); //=> true
1964 * R.gte(2, 3); //=> false
1965 * R.gte('a', 'z'); //=> false
1966 * R.gte('z', 'a'); //=> true
1967 * ```
1968 */
1969export function gte(__: Placeholder, b: number): (a: number) => boolean;
1970export function gte(__: Placeholder): (b: number, a: number) => boolean;
1971export function gte(a: number, b: number): boolean;
1972export function gte(a: string, b: string): boolean;
1973export function gte(a: number): (b: number) => boolean;
1974
1975/**
1976 * Returns whether or not an object has an own property with the specified name.
1977 *
1978 * @example
1979 * ```typescript
1980 * const hasName = R.has('name');
1981 * hasName({name: 'alice'}); //=> true
1982 * hasName({name: 'bob'}); //=> true
1983 * hasName({}); //=> false
1984 *
1985 * const point = {x: 0, y: 0};
1986 * const pointHas = R.has(R.__, point);
1987 * pointHas('x'); //=> true
1988 * pointHas('y'); //=> true
1989 * pointHas('z'); //=> false
1990 * ```
1991 */
1992export function has(__: Placeholder, obj: unknown): (s: string) => boolean;
1993export function has(__: Placeholder): <P extends string>(obj: unknown, s: P) => obj is ObjectHavingSome<P>;
1994export function has<P extends string>(s: P, obj: unknown): obj is ObjectHavingSome<P>;
1995export function has<P extends string>(s: P): (obj: unknown) => obj is ObjectHavingSome<P>;
1996
1997/**
1998 * Returns whether or not an object or its prototype chain has a property with the specified name.
1999 *
2000 * @example
2001 * ```typescript
2002 * class Rectangle {
2003 * constructor(public width: number, public height: number) {}
2004 *
2005 * area() {
2006 * return this.width * this.height;
2007 * }
2008 * }
2009 *
2010 * const square = new Rectangle(2, 2);
2011 * R.hasIn('width', square); //=> true
2012 * R.hasIn('area', square); //=> true
2013 * ```
2014 */
2015export function hasIn<T>(s: string, obj: T): boolean;
2016export function hasIn(s: string): <T>(obj: T) => boolean;
2017
2018/**
2019 * Returns whether or not a path exists in an object. Only the object's own properties are checked.
2020 *
2021 * See also {@link has}.
2022 *
2023 * @example
2024 * ```typescript
2025 * R.hasPath(['a', 'b'], {a: {b: 2}}); // => true
2026 * R.hasPath(['a', 'b'], {a: {b: undefined}}); // => true
2027 * R.hasPath(['a', 'b'], {a: {c: 2}}); // => false
2028 * R.hasPath(['a', 'b'], {}); // => false
2029 * ```
2030 */
2031export function hasPath<T>(list: readonly string[], obj: T): boolean;
2032export function hasPath(list: readonly string[]): <T>(obj: T) => boolean;
2033
2034/**
2035 * Returns the first element in a list.
2036 * In some libraries this function is named `first`.
2037 *
2038 * See also {@link tail}, {@link init}, {@link last}.
2039 *
2040 * @example
2041 * ```typescript
2042 * R.head(['fi', 'fo', 'fum']); //=> 'fi'
2043 * R.head([]); //=> undefined
2044 *
2045 * R.head('abc'); //=> 'a'
2046 * R.head(''); //=> ''
2047 * ```
2048 */
2049export function head(str: string): string;
2050export function head(list: readonly []): undefined;
2051export function head<T>(list: readonly T[]): T | undefined;
2052
2053/**
2054 * Returns `true` if its arguments are identical, `false` otherwise.
2055 * Values are identical if they reference the same memory.
2056 * `NaN` is identical to `NaN`; `0` and `-0` are not identical.
2057 *
2058 * @note This is merely a curried version of ES6 `Object.is`.
2059 *
2060 * @example
2061 * ```typescript
2062 * const o = {};
2063 * R.identical(o, o); //=> true
2064 * R.identical(1, 1); //=> true
2065 * R.identical<string | number>(1, '1'); //=> false
2066 * R.identical([], []); //=> false
2067 * R.identical(0, -0); //=> false
2068 * R.identical(NaN, NaN); //=> true
2069 * ```
2070 */
2071export function identical<T>(a: T, b: T): boolean;
2072export function identical<T>(a: T): (b: T) => boolean;
2073
2074/**
2075 * A function that returns its argument.
2076 * Good as a default or placeholder function.
2077 *
2078 * @example
2079 * ```typescript
2080 * R.identity(1); //=> 1
2081 *
2082 * const obj = {};
2083 * R.identity(obj) === obj; //=> true
2084 * ```
2085 */
2086export function identity<T>(a: T): T;
2087
2088/**
2089 * Creates a function that will process either the onTrue or the onFalse function depending upon the result
2090 * of the condition predicate.
2091 *
2092 * See also {@link unless}, {@link when}, {@link cond}.
2093 *
2094 * @example
2095 * ```typescript
2096 * const incCount = R.ifElse(
2097 * R.has('count'),
2098 * R.over(R.lensProp<{ count: number; }>('count'), R.inc),
2099 * R.assoc('count', 1)
2100 * );
2101 * incCount({ count: 1 }); //=> { count: 2 }
2102 * ```
2103 */
2104export function ifElse<T, TF extends T, TOnTrueResult, TOnFalseResult>(
2105 pred: PredTypeguard<T, TF>,
2106 onTrue: (a: TF) => TOnTrueResult,
2107 onFalse: (a: Exclude<T, TF>) => TOnFalseResult,
2108): (a: T) => TOnTrueResult | TOnFalseResult;
2109export function ifElse<TArgs extends any[], TOnTrueResult, TOnFalseResult>(
2110 fn: Pred<TArgs>,
2111 onTrue: (...args: TArgs) => TOnTrueResult,
2112 onFalse: (...args: TArgs) => TOnFalseResult,
2113): (...args: TArgs) => TOnTrueResult | TOnFalseResult;
2114
2115/**
2116 * Increments its argument.
2117 *
2118 * See also {@link dec}.
2119 *
2120 * @example
2121 * ```typescript
2122 * R.inc(42); //=> 43
2123 * ```
2124 */
2125export function inc(n: number): number;
2126
2127/**
2128 * Returns `true` if the specified value is equal, in `R.equals` terms,
2129 * to at least one element of the given list; `false` otherwise.
2130 * Also works with strings.
2131 *
2132 * See also {@link any}.
2133 *
2134 * @example
2135 * ```typescript
2136 * R.includes(3, [1, 2, 3]); //=> true
2137 * R.includes(4, [1, 2, 3]); //=> false
2138 * R.includes([42], [[42]]); //=> true
2139 * R.includes('ba', 'banana'); //=> true
2140 * R.includes({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true
2141 * ```
2142 */
2143export function includes(__: Placeholder, list: readonly string[] | string): (s: string) => boolean;
2144export function includes<T>(__: Placeholder, list: readonly T[]): (target: T) => boolean;
2145export function includes(__: Placeholder): (list: readonly string[] | string, s: string) => boolean;
2146export function includes<T>(__: Placeholder): (list: readonly T[], target: T) => boolean;
2147export function includes(s: string, list: readonly string[] | string): boolean;
2148export function includes(s: string): (list: readonly string[] | string) => boolean;
2149export function includes<T>(target: T, list: readonly T[]): boolean;
2150export function includes<T>(target: T): (list: readonly T[]) => boolean;
2151
2152/**
2153 * Given a function that generates a key,
2154 * turns a list of objects into an object indexing the objects by the given key.
2155 *
2156 * @note If multiple objects generate the same value for the indexing key
2157 * only the last value will be included in the generated object.
2158 *
2159 * Acts as a transducer if a transformer is given in list position.
2160 *
2161 * See also {@link groupBy}, {@link transduce}.
2162 *
2163 * @example
2164 * ```typescript
2165 * const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
2166 * R.indexBy(R.prop('id'), list);
2167 * //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
2168 * ```
2169 */
2170export function indexBy<T, K extends string | number = string>(fn: (a: T) => K, list: readonly T[]): { [key in K]: T };
2171export function indexBy<T, K extends string | number | undefined = string>(
2172 fn: (a: T) => K,
2173 list: readonly T[],
2174): { [key in NonNullable<K>]?: T };
2175export function indexBy<T, K extends string | number = string>(
2176 fn: (a: T) => K,
2177): (list: readonly T[]) => { [key in K]: T };
2178export function indexBy<T, K extends string | number | undefined = string>(
2179 fn: (a: T) => K | undefined,
2180): (list: readonly T[]) => { [key in NonNullable<K>]?: T };
2181
2182/**
2183 * Returns the position of the first occurrence of an item in an array,
2184 * or -1 if the item is not included in the array.
2185 * {@link equals `R.equals`} is used to determine equality.
2186 *
2187 * See also {@link lastIndexOf}, {@link findIndex}.
2188 *
2189 * @example
2190 * ```typescript
2191 * R.indexOf(3, [1,2,3,4]); //=> 2
2192 * R.indexOf(10, [1,2,3,4]); //=> -1
2193 * ```
2194 */
2195export function indexOf(target: string, list: readonly string[] | string): number;
2196export function indexOf(target: string): (list: readonly string[] | string) => number;
2197export function indexOf<T>(target: T, list: readonly T[]): number;
2198export function indexOf<T>(target: T): (list: readonly T[]) => number;
2199
2200/**
2201 * Returns all but the last element of the given list or string.
2202 *
2203 * See also {@link last}, {@link head}, {@link tail}.
2204 *
2205 * @example
2206 * ```typescript
2207 * R.init([1, 2, 3]); //=> [1, 2]
2208 * R.init([1, 2]); //=> [1]
2209 * R.init([1]); //=> []
2210 * R.init([]); //=> []
2211 *
2212 * R.init('abc'); //=> 'ab'
2213 * R.init('ab'); //=> 'a'
2214 * R.init('a'); //=> ''
2215 * R.init(''); //=> ''
2216 * ```
2217 */
2218export function init<T>(list: readonly T[]): T[];
2219export function init(list: string): string;
2220
2221/**
2222 * Takes a predicate `pred`, a list `xs`, and a list `ys`,
2223 * and returns a list `xs'` comprising each of the elements of `xs`
2224 * which is equal to one or more elements of `ys` according to `pred`.
2225 *
2226 * `pred` must be a binary function expecting an element from each list.
2227 *
2228 * `xs`, `ys`, and `xs'` are treated as sets, semantically, so ordering should not be significant,
2229 * but since `xs'` is ordered the implementation guarantees
2230 * that its values are in the same order as they appear in `xs`.
2231 * Duplicates are not removed, so `xs'` may contain duplicates if `xs` contains duplicates.
2232 *
2233 * See also {@link intersection}.
2234 *
2235 * @example
2236 * ```typescript
2237 * R.innerJoin(
2238 * (record, id) => record.id === id,
2239 * [{id: 824, name: 'Richie Furay'},
2240 * {id: 956, name: 'Dewey Martin'},
2241 * {id: 313, name: 'Bruce Palmer'},
2242 * {id: 456, name: 'Stephen Stills'},
2243 * {id: 177, name: 'Neil Young'}],
2244 * [177, 456, 999]
2245 * );
2246 * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
2247 * ```
2248 */
2249export function innerJoin<T1, T2>(pred: (a: T1, b: T2) => boolean, list1: readonly T1[], list2: readonly T2[]): T1[];
2250export function innerJoin<T1, T2>(
2251 pred: (a: T1, b: T2) => boolean,
2252): (list1: readonly T1[], list2: readonly T2[]) => T1[];
2253export function innerJoin<T1, T2>(
2254 pred: (a: T1, b: T2) => boolean,
2255 list1: readonly T1[],
2256): (list2: readonly T2[]) => T1[];
2257
2258/**
2259 * Returns a copy of the list with the element inserted at the index.
2260 *
2261 * @example
2262 * ```typescript
2263 * R.insert<string | number>(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]
2264 * ```
2265 */
2266export function insert<T>(index: number, elt: T, list: readonly T[]): T[];
2267export function insert<T>(index: number, elt: T): (list: readonly T[]) => T[];
2268export function insert(index: number): <T>(elt: T, list: readonly T[]) => T[];
2269
2270/**
2271 * Returns a copy of the list with the elements inserted at the index.
2272 *
2273 * @example
2274 * ```typescript
2275 * R.insertAll<string | number>(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4]
2276 * ```
2277 */
2278export function insertAll<T>(index: number, elts: readonly T[], list: readonly T[]): T[];
2279export function insertAll<T>(index: number, elts: readonly T[]): (list: readonly T[]) => T[];
2280export function insertAll(index: number): <T>(elts: readonly T[], list: readonly T[]) => T[];
2281
2282/**
2283 * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists.
2284 *
2285 * See also {@link innerJoin}.
2286 *
2287 * @example
2288 * ```typescript
2289 * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
2290 * ```
2291 */
2292export function intersection<T>(list1: readonly T[], list2: readonly T[]): T[];
2293export function intersection<T>(list1: readonly T[]): (list2: readonly T[]) => T[];
2294
2295/**
2296 * Creates a new list with the separator interposed between elements.
2297 *
2298 * Dispatches to the `intersperse` method of the second argument, if present.
2299 *
2300 * @example
2301 * ```typescript
2302 * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's']
2303 * ```
2304 */
2305export function intersperse<T>(separator: T, list: readonly T[]): T[];
2306export function intersperse<T>(separator: T): (list: readonly T[]) => T[];
2307
2308/**
2309 * Transforms the items of the list with the transducer
2310 * and appends the transformed items to the accumulator
2311 * using an appropriate iterator function based on the accumulator type.
2312 *
2313 * The accumulator can be an array, string, object or a transformer.
2314 * Iterated items will be appended to arrays and concatenated to strings.
2315 * Objects will be merged directly or 2-item tuples will be merged as key, value pairs.
2316 *
2317 * The accumulator can also be a transformer object that provides:
2318 * - A 2-arity iterator function, which is passed directly to reduce.
2319 * - A 0-arity initial value function, which is used to provide the initial accumulator.
2320 * - A 1-arity result extraction function, which is used to convert the final accumulator into the return type.
2321 * In most cases is it is {@link identity `R.identity`}.
2322 *
2323 * The iteration is performed with {@link reduce `R.reduce`} after initializing the transducer.
2324 *
2325 * See also {@link transduce}.
2326 *
2327 * @example
2328 * ```typescript
2329 * const numbers = [1, 2, 3, 4];
2330 * const transducer = R.compose(R.map(R.add(1)), R.take(2));
2331 *
2332 * R.into([], transducer, numbers); //=> [2, 3]
2333 *
2334 * const intoArray = R.into([]);
2335 * intoArray(transducer, numbers); //=> [2, 3]
2336 * ```
2337 */
2338export function into<T>(acc: any, xf: AnyFunction, list: readonly T[]): T[];
2339export function into<T, R>(acc: any, xf: (...args: any[]) => R[], list: readonly T[]): R[];
2340export function into(acc: any, xf: AnyFunction): <T>(list: readonly T[]) => T[];
2341export function into(acc: any): <T>(xf: AnyFunction, list: readonly T[]) => T[];
2342
2343/**
2344 * Same as `R.invertObj`,
2345 * however this accounts for objects with duplicate values by putting the values into an array.
2346 *
2347 * See also {@link invertObj}.
2348 *
2349 * @example
2350 * ```typescript
2351 * const raceResultsByFirstName = {
2352 * first: 'alice',
2353 * second: 'jake',
2354 * third: 'alice',
2355 * };
2356 * R.invert(raceResultsByFirstName);
2357 * //=> { 'alice': ['first', 'third'], 'jake': ['second'] }
2358 * ```
2359 */
2360export function invert<T>(obj: T): { [index: string]: string[] };
2361
2362/**
2363 * Returns a new object with the keys of the given object as values, and the values of the given object as keys.
2364 *
2365 * @note If multiple objects generate the same value for the indexing key
2366 * only the last value will be included in the generated object.
2367 *
2368 * See also {@link invert}.
2369 *
2370 * @example
2371 * ```typescript
2372 * const raceResults = {
2373 * first: 'alice',
2374 * second: 'jake'
2375 * };
2376 * R.invertObj(raceResults);
2377 * //=> { 'alice': 'first', 'jake':'second' }
2378 *
2379 * // Alternatively:
2380 * const raceResults = ['alice', 'jake'];
2381 * R.invertObj(raceResults);
2382 * //=> { 'alice': '0', 'jake':'1' }
2383 * ```
2384 */
2385export function invertObj(obj: { [index: string]: string } | { [index: number]: string }): { [index: string]: string };
2386
2387/**
2388 * Turns a named method with a specified arity into a function that can be called directly
2389 * supplied with arguments and a target object.
2390 *
2391 * The returned function is curried and accepts `arity + 1` parameters
2392 * where the final parameter is the target object.
2393 *
2394 * @example
2395 * ```typescript
2396 * const sliceFrom = R.invoker<(start: number, s: string) => string>(1, 'slice');
2397 * sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm'
2398 * const sliceFrom6 = R.invoker<(start: number, end: number, s: string) => string>(2, 'slice')(6);
2399 * sliceFrom6(8, 'abcdefghijklm'); //=> 'gh'
2400 *
2401 * const dog = {
2402 * speak: async () => 'Woof!'
2403 * };
2404 * const speak = R.invoker<(speaker: { speak: () => Promise<string> }) => Promise<string>>(0, 'speak');
2405 * speak(dog).then(console.log) //~> 'Woof!'
2406 * ```
2407 */
2408export function invoker(arity: number, method: string): (...args: unknown[]) => any;
2409
2410/**
2411 * See if an object (`val`) is an instance of the supplied constructor.
2412 * This function will check up the inheritance chain, if any.
2413 * If `val` was created using `Object.create`, `R.is(Object, val) === true`.
2414 *
2415 * See also {@link propIs}.
2416 */
2417export function is<C extends AnyFunction>(ctor: C, val: any): val is ReturnType<C>;
2418export function is<C extends AnyConstructor>(ctor: C, val: any): val is InstanceType<C>;
2419export function is<C extends AnyFunction>(ctor: C): (val: any) => val is ReturnType<C>;
2420export function is<C extends AnyConstructor>(ctor: C): (val: any) => val is InstanceType<C>;
2421
2422/**
2423 * Returns `true` if the given value is its type's empty value; `false` otherwise.
2424 *
2425 * See also {@link empty}.
2426 *
2427 * @example
2428 * ```typescript
2429 * R.isEmpty([1, 2, 3]); //=> false
2430 * R.isEmpty([]); //=> true
2431 * R.isEmpty(''); //=> true
2432 * R.isEmpty(null); //=> false
2433 * R.isEmpty({}); //=> true
2434 * R.isEmpty({length: 0}); //=> false
2435 * R.isEmpty(Uint8Array.from([])); //=> true
2436 * ```
2437 */
2438export function isEmpty(value: any): boolean;
2439
2440/**
2441 * Checks if the input value is `null` or `undefined`.
2442 *
2443 * @example
2444 * ```typescript
2445 * R.isNil(null); //=> true
2446 * R.isNil(undefined); //=> true
2447 * R.isNil(0); //=> false
2448 * R.isNil([]); //=> false
2449 * ```
2450 */
2451export function isNil(value: any): value is null | undefined;
2452
2453/**
2454 * Returns a string made by inserting the given separator between each element
2455 * and concatenating all the elements into a single string.
2456 *
2457 * See also {@link split}.
2458 *
2459 * @example
2460 * ```typescript
2461 * const spacer = R.join(' ');
2462 * spacer(['a', 2, 3.4]); //=> 'a 2 3.4'
2463 * R.join('|', [1, 2, 3]); //=> '1|2|3'
2464 * ```
2465 */
2466export function join(x: string, xs: readonly any[]): string;
2467export function join(x: string): (xs: readonly any[]) => string;
2468
2469/**
2470 * Applies a list of functions to a list of values.
2471 *
2472 * See also {@link applySpec}.
2473 *
2474 * @example
2475 * ```typescript
2476 * const getRange = R.juxt([Math.min, Math.max]);
2477 * getRange(3, 4, 9, -3); //=> [-3, 9]
2478 * ```
2479 */
2480export function juxt<A extends any[], R1>(fns: [(...args: A) => R1]): (...args: A) => [R1];
2481export function juxt<A extends any[], R1, R2>(fns: [(...args: A) => R1, (...args: A) => R2]): (...args: A) => [R1, R2];
2482export function juxt<A extends any[], R1, R2, R3>(
2483 fns: [(...args: A) => R1, (...args: A) => R2, (...args: A) => R3],
2484): (...args: A) => [R1, R2, R3];
2485export function juxt<A extends any[], R1, R2, R3, R4>(
2486 fns: [(...args: A) => R1, (...args: A) => R2, (...args: A) => R3, (...args: A) => R4],
2487): (...args: A) => [R1, R2, R3, R4];
2488export function juxt<A extends any[], R1, R2, R3, R4, R5>(
2489 fns: [(...args: A) => R1, (...args: A) => R2, (...args: A) => R3, (...args: A) => R4, (...args: A) => R5],
2490): (...args: A) => [R1, R2, R3, R4, R5];
2491export function juxt<A extends any[], U>(fns: ReadonlyArray<(...args: A) => U>): (...args: A) => U[];
2492
2493/**
2494 * Returns a list containing the names of all the enumerable own properties of the supplied object.
2495 *
2496 * @note The order of the output array is not guaranteed to be consistent across different JS platforms.
2497 *
2498 * See also {@link keysIn}, {@link values}, {@link toPairs}.
2499 *
2500 * @example
2501 * ```typescript
2502 * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']
2503 * ```
2504 */
2505export function keys<T extends object>(x: T): Array<keyof T>;
2506export function keys<T>(x: T): string[];
2507
2508/**
2509 * Returns a list containing the names of all the properties of the supplied object,
2510 * including prototype properties.
2511 *
2512 * @note The order of the output array is not guaranteed to be consistent across different JS platforms.
2513 *
2514 * See also {@link keys}, {@link valuesIn}.
2515 *
2516 * @example
2517 * ```typescript
2518 * class F {
2519 * y = 'Y';
2520 * constructor(public x: string = 'X') {}
2521 * }
2522 *
2523 * const f = new F();
2524 * R.keysIn(f); //=> ['x', 'y']
2525 * ```
2526 */
2527export function keysIn<T>(obj: T): string[];
2528
2529/**
2530 * Returns the last element of the given list or string.
2531 *
2532 * See also {@link init}, {@link head}, {@link tail}.
2533 *
2534 * @example
2535 * ```typescript
2536 * R.last(['fi', 'fo', 'fum']); //=> 'fum'
2537 * R.last([]); //=> undefined
2538 *
2539 * R.last('abc'); //=> 'c'
2540 * R.last(''); //=> ''
2541 * ```
2542 */
2543export function last(str: string): string;
2544export function last(list: readonly []): undefined;
2545export function last<T>(list: readonly T[]): T | undefined;
2546
2547/**
2548 * Returns the position of the last occurrence of an item in an array,
2549 * or `-1` if the item is not included in the array.
2550 * {@link equals `R.equals`} is used to determine equality.
2551 *
2552 * See also {@link indexOf}, {@link findLastIndex}.
2553 *
2554 * @example
2555 * ```typescript
2556 * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
2557 * R.lastIndexOf(10, [1,2,3,4]); //=> -1
2558 * ```
2559 */
2560export function lastIndexOf(target: string, list: readonly string[] | string): number;
2561export function lastIndexOf(target: string): (list: readonly string[] | string) => number;
2562export function lastIndexOf<T>(target: T, list: readonly T[]): number;
2563export function lastIndexOf<T>(target: T): (list: readonly T[]) => number;
2564
2565/**
2566 * Returns the number of elements in the array by returning `list.length`.
2567 *
2568 * @example
2569 * ```typescript
2570 * R.length([]); //=> 0
2571 * R.length([1, 2, 3]); //=> 3
2572 * ```
2573 */
2574export function length<T extends ArrayLike<unknown>>(list: T): number;
2575
2576/**
2577 * Returns a lens for the given getter and setter functions.
2578 * The getter "gets" the value of the focus; the setter "sets" the value of the focus.
2579 * The setter should not mutate the data structure.
2580 *
2581 * See also {@link view}, {@link set}, {@link over}, {@link lensIndex}, {@link lensProp}.
2582 */
2583export function lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>;
2584
2585/**
2586 * Returns a lens whose focus is the specified index.
2587 *
2588 * See also {@link view}, {@link set}, {@link over}, {@link nth}, {@link lens}.
2589 *
2590 * @example
2591 * ```typescript
2592 * const headLens = R.lensIndex<string>(0);
2593 *
2594 * R.view(headLens, ['a', 'b', 'c']); //=> 'a'
2595 * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c']
2596 * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c']
2597 * ```
2598 */
2599export function lensIndex<A>(n: number): Lens<A[], A>;
2600export function lensIndex<A extends any[], N extends number>(n: N): Lens<A, A[N]>;
2601
2602/**
2603 * Returns a lens whose focus is the specified path.
2604 *
2605 * See also {@link view}, {@link set}, {@link over}, {@link lens}.
2606 *
2607 * @example
2608 * ```typescript
2609 * const xHeadYLens = R.lensPath<{ x: { y: number; z: number; }[]; }, 'x', 0, 'y'>(['x', 0, 'y']);
2610 *
2611 * R.view(xHeadYLens, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
2612 * //=> 2
2613 * R.set(xHeadYLens, 1, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
2614 * //=> {x: [{y: 1, z: 3}, {y: 4, z: 5}]}
2615 * R.over(xHeadYLens, R.negate, {x: [{y: 2, z: 3}, {y: 4, z: 5}]});
2616 * //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]}
2617 * ```
2618 */
2619export function lensPath<S, K0 extends keyof S = keyof S>(path: [K0]): Lens<S, S[K0]>;
2620export function lensPath<S, K0 extends keyof S = keyof S, K1 extends keyof S[K0] = keyof S[K0]>(
2621 path: [K0, K1],
2622): Lens<S, S[K0][K1]>;
2623export function lensPath<
2624 S,
2625 K0 extends keyof S = keyof S,
2626 K1 extends keyof S[K0] = keyof S[K0],
2627 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
2628>(path: [K0, K1, K2]): Lens<S, S[K0][K1][K2]>;
2629export function lensPath<
2630 S,
2631 K0 extends keyof S = keyof S,
2632 K1 extends keyof S[K0] = keyof S[K0],
2633 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
2634 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
2635>(path: [K0, K1, K2, K3]): Lens<S, S[K0][K1][K2][K3]>;
2636export function lensPath<
2637 S,
2638 K0 extends keyof S = keyof S,
2639 K1 extends keyof S[K0] = keyof S[K0],
2640 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
2641 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
2642 K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
2643>(path: [K0, K1, K2, K3, K4]): Lens<S, S[K0][K1][K2][K3][K4]>;
2644export function lensPath<
2645 S,
2646 K0 extends keyof S = keyof S,
2647 K1 extends keyof S[K0] = keyof S[K0],
2648 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
2649 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
2650 K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
2651 K5 extends keyof S[K0][K1][K2][K3][K4] = keyof S[K0][K1][K2][K3][K4],
2652>(path: [K0, K1, K2, K3, K4, K5]): Lens<S, S[K0][K1][K2][K3][K4][K5]>;
2653
2654export function lensPath<S = any, A = any>(path: Path): Lens<S, A>;
2655
2656/**
2657 * Returns a lens whose focus is the specified property.
2658 *
2659 * See also {@link view}, {@link set}, {@link over}, {@link lens}.
2660 *
2661 * @example
2662 * ```typescript
2663 * type Point = { x: number; y: number; };
2664 *
2665 * const xLens = R.lensProp<Point, 'x'>('x');
2666 *
2667 * R.view(xLens, {x: 1, y: 2}); //=> 1
2668 * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
2669 * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
2670 * ```
2671 */
2672export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;
2673
2674/**
2675 * "lifts" a function of arity > 1 so that it may "map over" a list,
2676 * `Function` or other object that satisfies the FantasyLand Apply spec.
2677 *
2678 * See also {@link liftN}.
2679 *
2680 * @example
2681 * ```typescript
2682 * const madd3 = R.lift((a: number, b: number, c: number) => a + b + c);
2683 *
2684 * madd3([100, 200], [30, 40], [5, 6, 7]); //=> [135, 136, 137, 145, 146, 147, 235, 236, 237, 245, 246, 247]
2685 *
2686 * const madd5 = R.lift((a: number, b: number, c: number, d: number, e: number) => a + b + c + d + e);
2687 *
2688 * madd5([10, 20], [1], [2, 3], [4], [100, 200]); //=> [117, 217, 118, 218, 127, 227, 128, 228]
2689 * ```
2690 */
2691export function lift<F extends AnyFunction>(
2692 fn: F,
2693): {
2694 (...args: ToTupleOfArray<Parameters<F>>): Array<ReturnType<F>>;
2695 <R>(...args: ToTupleOfFunction<R, Parameters<F>>): (arg: R) => ReturnType<F>;
2696};
2697
2698/**
2699 * "lifts" a function to be the specified arity,
2700 * so that it may "map over" that many lists, Functions or other objects
2701 * that satisfy the FantasyLand Apply spec.
2702 *
2703 * See also {@link lift}, {@link ap}.
2704 *
2705 * @example
2706 * ```typescript
2707 * const madd3 = R.liftN(3, (...args: [number, number, number]) => R.sum(args));
2708 * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
2709 * ```
2710 */
2711export function liftN<N extends number, F extends AnyFunction>(
2712 n: N,
2713 fn: F,
2714): {
2715 (...args: Take<N, ToTupleOfArray<Parameters<F>>>): Array<ReturnType<F>>;
2716 <R>(...args: Take<N, ToTupleOfFunction<R, Parameters<F>>>): (arg: R) => ReturnType<F>;
2717};
2718
2719/**
2720 * Returns `true` if the first parameter is less than the second; `false` otherwise.
2721 *
2722 * See also {@link gt}, {@link gte}, {@link lte}.
2723 *
2724 * @example
2725 * ```typescript
2726 * R.lt(2, 1); //=> false
2727 * R.lt(2, 2); //=> false
2728 * R.lt(2, 3); //=> true
2729 * R.lt('a', 'z'); //=> true
2730 * R.lt('z', 'a'); //=> false
2731 * ```
2732 */
2733export function lt(__: Placeholder, b: number): (a: number) => boolean;
2734export function lt(__: Placeholder): (b: number, a: number) => boolean;
2735export function lt(a: number, b: number): boolean;
2736export function lt(a: string, b: string): boolean;
2737export function lt(a: number): (b: number) => boolean;
2738
2739/**
2740 * Returns `true` if the first parameter is less than or equal to the second; `false` otherwise.
2741 *
2742 * See also {@link gt}, {@link gte}, {@link lt}.
2743 *
2744 * @example
2745 * ```typescript
2746 * R.lte(2, 1); //=> false
2747 * R.lte(2, 2); //=> true
2748 * R.lte(2, 3); //=> true
2749 * R.lte('a', 'z'); //=> true
2750 * R.lte('z', 'a'); //=> false
2751 * ```
2752 */
2753export function lte(__: Placeholder, b: number): (a: number) => boolean;
2754export function lte(__: Placeholder): (b: number, a: number) => boolean;
2755export function lte(a: number, b: number): boolean;
2756export function lte(a: string, b: string): boolean;
2757export function lte(a: number): (b: number) => boolean;
2758
2759/**
2760 * Takes a function and a functor,
2761 * applies the function to each of the functor's values,
2762 * and returns a functor of the same shape.
2763 *
2764 * Ramda provides suitable `map` implementations for `Array` and `Object`,
2765 * so this function may be applied to `[1, 2, 3]` or `{x: 1, y: 2, z: 3}`.
2766 *
2767 * Dispatches to the `map` method of the second argument, if present.
2768 *
2769 * Acts as a transducer if a transformer is given in list position.
2770 *
2771 * Also treats functions as functors and will compose them together.
2772 *
2773 * See also {@link addIndex}, {@link pluck}, {@link project}, {@link transduce}.
2774 *
2775 * @example
2776 * ```typescript
2777 * const double = x => x * 2;
2778 *
2779 * R.map(double, [1, 2, 3]); //=> [2, 4, 6]
2780 *
2781 * R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6}
2782 * ```
2783 */
2784export function map<T, U>(fn: (x: T) => U, list: readonly T[]): U[];
2785export function map<T, U>(fn: (x: T) => U): (list: readonly T[]) => U[];
2786export function map<T, U>(fn: (x: T[keyof T & keyof U] | ValueOfUnion<T>) => U[keyof T & keyof U], list: T): U;
2787export function map<T, U>(fn: (x: T[keyof T & keyof U] | ValueOfUnion<T>) => U[keyof T & keyof U]): (list: T) => U;
2788export function map<T, U>(fn: (x: T) => U, obj: Functor<T>): Functor<U>; // used in functors
2789export function map<T, U>(fn: (x: T) => U): (obj: Functor<T>) => Functor<U>; // used in functors
2790
2791/**
2792 * The `mapAccum` function behaves like a combination of map and reduce;
2793 * it applies a function to each element of a list,
2794 * passing an accumulating parameter from left to right,
2795 * and returning a final value of this accumulator together with the new list.
2796 *
2797 * The iterator function receives two arguments, `acc` and `value`,
2798 * and should return a tuple `[acc, value]`.
2799 *
2800 * See also {@link scan}, {@link addIndex}, {@link mapAccumRight}.
2801 *
2802 * @example
2803 * ```typescript
2804 * const digits = ['1', '2', '3', '4'];
2805 * const appender = (a: string, b: string) => [a + b, a + b] as const;
2806 *
2807 * R.mapAccum(appender, '0', digits); //=> ['01234', ['01', '012', '0123', '01234']]
2808 * ```
2809 */
2810export function mapAccum<T, U, TResult>(
2811 fn: (acc: U, value: T) => [U, TResult],
2812 acc: U,
2813 list: readonly T[],
2814): [U, TResult[]];
2815export function mapAccum<T, U, TResult>(
2816 fn: (acc: U, value: T) => [U, TResult],
2817): (acc: U, list: readonly T[]) => [U, TResult[]];
2818export function mapAccum<T, U, TResult>(
2819 fn: (acc: U, value: T) => [U, TResult],
2820 acc: U,
2821): (list: readonly T[]) => [U, TResult[]];
2822
2823/**
2824 * Applies a function to each element of a list,
2825 * passing an accumulating parameter from right to left,
2826 * and returning a final value of this accumulator together with the new list.
2827 *
2828 * Similar to `R.mapAccum`, except moves through the input list from the right to the left.
2829 *
2830 * The iterator function receives two arguments, `acc` and `value`,
2831 * and should return a tuple `[acc, value]`.
2832 *
2833 * See also {@link addIndex}, {@link mapAccum}.
2834 *
2835 * @example
2836 * ```typescript
2837 * const digits = ['1', '2', '3', '4'];
2838 * const appender = (a: string, b: string) => [b + a, b + a] as const;
2839 *
2840 * R.mapAccumRight(appender, '5', digits); //=> ['12345', ['12345', '2345', '345', '45']]
2841 * ```
2842 */
2843export function mapAccumRight<T, U, TResult>(
2844 fn: (acc: U, value: T) => [U, TResult],
2845 acc: U,
2846 list: readonly T[],
2847): [U, TResult[]];
2848export function mapAccumRight<T, U, TResult>(
2849 fn: (acc: U, value: T) => [U, TResult],
2850): (acc: U, list: readonly T[]) => [U, TResult[]];
2851export function mapAccumRight<T, U, TResult>(
2852 fn: (acc: U, value: T) => [U, TResult],
2853 acc: U,
2854): (list: readonly T[]) => [U, TResult[]];
2855
2856/**
2857 * Like mapObj, but but passes additional arguments to the predicate function.
2858 */
2859type PartialRecord<K extends keyof any, T> = {
2860 [P in K]?: T;
2861};
2862export function mapObjIndexed<T, TResult, TKey extends string>(
2863 fn: (value: T, key: TKey, obj?: Record<TKey, T>) => TResult,
2864 obj: Record<TKey, T>,
2865): Record<TKey, TResult>;
2866export function mapObjIndexed<T, TResult, TKey extends string>(
2867 fn: (value: T, key: TKey, obj?: Record<TKey, T>) => TResult,
2868 obj: PartialRecord<TKey, T>,
2869): PartialRecord<TKey, TResult>;
2870export function mapObjIndexed<T, TResult, TKey extends string>(
2871 fn: (value: T, key: TKey, obj?: Record<TKey, T>) => TResult,
2872): (obj: Record<TKey, T>) => Record<TKey, TResult>;
2873export function mapObjIndexed<T, TResult, TKey extends string>(
2874 fn: (value: T, key: TKey, obj?: PartialRecord<TKey, T>) => TResult,
2875): (obj: Record<TKey, T>) => PartialRecord<TKey, TResult>;
2876export function mapObjIndexed<T, TResult>(
2877 fn: (
2878 value: T,
2879 key: string,
2880 obj?: {
2881 [key: string]: T;
2882 },
2883 ) => TResult,
2884 obj: {
2885 [key: string]: T;
2886 },
2887): {
2888 [key: string]: TResult;
2889};
2890
2891/**
2892 * Tests a `RegExp` against a String.
2893 *
2894 * @note This function will return an empty array when there are no matches.
2895 * This differs from `String.prototype.match` which returns `null` when there are no matches.
2896 *
2897 * @example
2898 * ```typescript
2899 * R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
2900 * R.match(/a/, 'b'); //=> []
2901 * ```
2902 */
2903export function match(regexp: RegExp, str: string): string[];
2904export function match(regexp: RegExp): (str: string) => string[];
2905
2906/**
2907 * `mathMod` behaves like the modulo operator should mathematically,
2908 * unlike the `%` operator (and by extension, `R.modulo`).
2909 * So while `-17 % 5` is `-2`, `mathMod(-17, 5)` is `3`.
2910 * `mathMod` requires integer arguments,
2911 * and returns `NaN` when the modulus is zero or negative.
2912 *
2913 * See also {@link modulo}.
2914 *
2915 * @example
2916 * ```typescript
2917 * R.mathMod(-17, 5); //=> 3
2918 * R.mathMod(17, 5); //=> 2
2919 * R.mathMod(17, -5); //=> NaN
2920 * R.mathMod(17, 0); //=> NaN
2921 * R.mathMod(17.2, 5); //=> NaN
2922 * R.mathMod(17, 5.3); //=> NaN
2923 *
2924 * const clock = R.mathMod(R.__, 12);
2925 * clock(15); //=> 3
2926 * clock(24); //=> 0
2927 *
2928 * const seventeenMod = R.mathMod(17);
2929 * seventeenMod(3); //=> 2
2930 * seventeenMod(4); //=> 1
2931 * seventeenMod(10); //=> 7
2932 * ```
2933 */
2934export function mathMod(__: Placeholder, b: number): (a: number) => number;
2935export function mathMod(__: Placeholder): (b: number, a: number) => number;
2936export function mathMod(a: number, b: number): number;
2937export function mathMod(a: number): (b: number) => number;
2938
2939/**
2940 * Returns the larger of its two arguments.
2941 *
2942 * See also {@link maxBy}, {@link min}, {@link minBy}.
2943 *
2944 * @example
2945 * ```typescript
2946 * R.max(789, 123); //=> 789
2947 * R.max('a', 'b'); //=> 'b'
2948 * ```
2949 */
2950export function max<T extends Ord>(a: T, b: T): T;
2951export function max<T extends Ord>(a: T): (b: T) => T;
2952
2953/**
2954 * Takes a function and two values, and returns whichever value produces
2955 * the larger result when passed to the provided function.
2956 *
2957 * See also {@link max}, {@link min}, {@link minBy}.
2958 *
2959 * @example
2960 * ```typescript
2961 * // square :: Number -> Number
2962 * const square = (n: number) => n * n;
2963 *
2964 * R.maxBy(square, -3, 2); //=> -3
2965 *
2966 * R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5
2967 * R.reduce(R.maxBy(square), 0, [] as number[]); //=> 0
2968 * ```
2969 */
2970export function maxBy<T>(keyFn: (a: T) => Ord, a: T, b: T): T;
2971export function maxBy<T>(keyFn: (a: T) => Ord, a: T): (b: T) => T;
2972export function maxBy<T>(keyFn: (a: T) => Ord): _.F.Curry<(a: T, b: T) => T>;
2973
2974/**
2975 * Returns the mean of the given list of numbers.
2976 *
2977 * See also {@link median}.
2978 *
2979 * @example
2980 * ```typescript
2981 * R.mean([2, 7, 9]); //=> 6
2982 * R.mean([]); //=> NaN
2983 * ```
2984 */
2985export function mean(list: readonly number[]): number;
2986
2987/**
2988 * Returns the median of the given list of numbers.
2989 *
2990 * See also {@link mean}.
2991 *
2992 * @example
2993 * ```typescript
2994 * R.median([2, 9, 7]); //=> 7
2995 * R.median([7, 2, 10, 9]); //=> 8
2996 * R.median([]); //=> NaN
2997 * ```
2998 */
2999export function median(list: readonly number[]): number;
3000
3001/**
3002 * Creates a new function that, when invoked,
3003 * caches the result of calling the given function for a given argument set and returns the result.
3004 * Subsequent calls to the memoized function with the same argument set will return the cached result.
3005 *
3006 * @example
3007 * ```typescript
3008 * let count = 0;
3009 * const factorial = R.memoizeWith(String, (n: number) => {
3010 * count += 1;
3011 * return R.product(R.range(1, n + 1));
3012 * });
3013 * factorial(5); //=> 120
3014 * factorial(5); //=> 120
3015 * factorial(5); //=> 120
3016 * count; //=> 1
3017 * ```
3018 */
3019export function memoizeWith<T extends AnyFunction>(keyFn: (...v: Parameters<T>) => string, fn: T): T;
3020
3021/**
3022 * Creates one new object with the own properties from a list of objects.
3023 * If a key exists in more than one object,
3024 * the value from the last object it exists in will be used.
3025 *
3026 * See also {@link reduce}.
3027 *
3028 * @example
3029 * ```typescript
3030 * R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3}
3031 * R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2}
3032 * ```
3033 */
3034export function mergeAll<Os extends readonly object[]>(list: Os): MergeAll<Os>;
3035
3036/**
3037 * Creates a new object with the own properties of the first object
3038 * merged with the own properties of the second object.
3039 *
3040 * If a key exists in both objects:
3041 * - and both values are objects, the two values will be recursively merged
3042 * - otherwise the value from the first object will be used.
3043 *
3044 * See also {@link mergeDeepRight}, {@link mergeDeepWith}, {@link mergeDeepWithKey}.
3045 *
3046 * @example
3047 * ```typescript
3048 * R.mergeDeepLeft({ name: 'fred', age: 10, contact: { email: 'moo@example.com' }},
3049 * { age: 40, contact: { email: 'baa@example.com' }});
3050 * //=> { name: 'fred', age: 10, contact: { email: 'moo@example.com' }}
3051 * ```
3052 */
3053export function mergeDeepLeft<O1 extends object, O2 extends object>(o1: O1, o2: O2): Merge<O1, O2, 'deep'>;
3054export function mergeDeepLeft<O1 extends object>(o1: O1): <O2 extends object>(o2: O2) => Merge<O1, O2, 'deep'>;
3055
3056/**
3057 * Creates a new object with the own properties of the first object
3058 * merged with the own properties of the second object.
3059 *
3060 * If a key exists in both objects:
3061 * - and both values are objects, the two values will be recursively merged
3062 * - otherwise the value from the second object will be used.
3063 *
3064 * See also {@link mergeDeepLeft}, {@link mergeDeepWith}, {@link mergeDeepWithKey}.
3065 *
3066 * @example
3067 * ```typescript
3068 * R.mergeDeepRight({ name: 'fred', age: 10, contact: { email: 'moo@example.com' }},
3069 * { age: 40, contact: { email: 'baa@example.com' }});
3070 * //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }}
3071 * ```
3072 */
3073export function mergeDeepRight<O1 extends object, O2 extends object>(o1: O1, o2: O2): Merge<O2, O1, 'deep'>;
3074export function mergeDeepRight<O1 extends object>(a: O1): <O2 extends object>(o2: O2) => Merge<O2, O1, 'deep'>;
3075
3076/**
3077 * Creates a new object with the own properties of the two provided objects.
3078 *
3079 * If a key exists in both objects:
3080 * - and both associated values are also objects then the values will be recursively merged.
3081 * - otherwise the provided function is applied to associated values
3082 * using the resulting value as the new value associated with the key.
3083 * If a key only exists in one object,
3084 * the value will be associated with the key of the resulting object.
3085 *
3086 * See also {@link mergeWith}, {@link mergeDeepWithKey}.
3087 *
3088 * @example
3089 * ```typescript
3090 * R.mergeDeepWith(R.concat,
3091 * { a: true, c: { values: [10, 20] }},
3092 * { b: true, c: { values: [15, 35] }});
3093 * //=> { a: true, b: true, c: { values: [10, 20, 15, 35] }}
3094 * ```
3095 */
3096export function mergeDeepWith<T1, T2>(fn: (x: any, z: any) => any, a: T1, b: T2): any;
3097export function mergeDeepWith<T1, T2>(fn: (x: any, z: any) => any, a: T1): (b: T2) => any;
3098export function mergeDeepWith<T1, T2>(fn: (x: any, z: any) => any): (a: T1, b: T2) => any;
3099
3100/**
3101 * Creates a new object with the own properties of the two provided objects. If a key exists in both objects:
3102 * and both associated values are also objects then the values will be recursively merged.
3103 * otherwise the provided function is applied to the key and associated values using the resulting value as
3104 * the new value associated with the key. If a key only exists in one object, the value will be associated with
3105 * the key of the resulting object.
3106 *
3107 * See also {@link mergeWith}, {@link mergeWithKey}, {@link mergeDeepWith}.
3108 *
3109 * @example
3110 * ```typescript
3111 * let concatValues = <T>(k: string, l: T, r: T) => k == 'values' ? R.concat(l, r) : r
3112 * R.mergeDeepWithKey(concatValues,
3113 * { a: true, c: { thing: 'foo', values: [10, 20] }},
3114 * { b: true, c: { thing: 'bar', values: [15, 35] }});
3115 * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }}
3116 * ```
3117 */
3118export function mergeDeepWithKey<T1, T2>(fn: (k: string, x: any, z: any) => any, a: T1, b: T2): any;
3119export function mergeDeepWithKey<T1, T2>(fn: (k: string, x: any, z: any) => any, a: T1): (b: T2) => any;
3120export function mergeDeepWithKey<T1, T2>(fn: (k: string, x: any, z: any) => any): (a: T1, b: T2) => any;
3121
3122/**
3123 * Create a new object with the own properties of the first object
3124 * merged with the own properties of the second object.
3125 * If a key exists in both objects,
3126 * the value from the first object will be used.
3127 *
3128 * See also {@link mergeRight}, {@link mergeDeepLeft}, {@link mergeWith}, {@link mergeWithKey}.
3129 *
3130 * @example
3131 * ```typescript
3132 * R.mergeLeft({ 'age': 40 }, { 'name': 'fred', 'age': 10 });
3133 * //=> { 'name': 'fred', 'age': 40 }
3134 *
3135 * const resetToDefault = R.mergeLeft({x: 0});
3136 * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2}
3137 * ```
3138 */
3139export function mergeLeft<O1 extends object, O2 extends object>(a: O1, b: O2): Merge<O1, O2, 'flat'>;
3140export function mergeLeft<O1 extends object>(a: O1): <O2 extends object>(b: O2) => Merge<O1, O2, 'flat'>;
3141
3142/**
3143 * Create a new object with the own properties of the first object merged with the own properties of the second object.
3144 * If a key exists in both objects, the value from the second object will be used.
3145 *
3146 * See also {@link mergeLeft}, {@link mergeDeepRight}, {@link mergeWith}, {@link mergeWithKey}.
3147 *
3148 * @example
3149 * ```typescript
3150 * R.mergeRight({ 'name': 'fred', 'age': 10 }, { 'age': 40 });
3151 * //=> { 'name': 'fred', 'age': 40 }
3152 *
3153 * const withDefaults = R.mergeRight({x: 0, y: 0});
3154 * withDefaults({y: 2}); //=> {x: 0, y: 2}
3155 * ```
3156 */
3157export function mergeRight<O1 extends object, O2 extends object>(a: O1, b: O2): Merge<O2, O1, 'flat'>;
3158export function mergeRight<O1 extends object>(a: O1): <O2 extends object>(b: O2) => Merge<O2, O1, 'flat'>;
3159
3160/**
3161 * Creates a new object with the own properties of the two provided objects.
3162 * If a key exists in both objects,
3163 * the provided function is applied to the values associated with the key in each object,
3164 * with the result being used as the value associated with the key in the returned object.
3165 * The key will be excluded from the returned object
3166 * if the resulting value is `undefined`.
3167 *
3168 * See also {@link mergeDeepWith}, {@link merge}, {@link mergeWithKey}.
3169 *
3170 * @example
3171 * ```typescript
3172 * R.mergeWith(R.concat,
3173 * { a: true, values: [10, 20] },
3174 * { b: true, values: [15, 35] });
3175 * //=> { a: true, b: true, values: [10, 20, 15, 35] }
3176 * ```
3177 */
3178export function mergeWith<U, V>(fn: (x: any, z: any) => any, a: U, b: V): any;
3179export function mergeWith<U>(fn: (x: any, z: any) => any, a: U): <V>(b: V) => any;
3180export function mergeWith(fn: (x: any, z: any) => any): <U, V>(a: U, b: V) => any;
3181
3182/**
3183 * Creates a new object with the own properties of the two provided objects.
3184 * If a key exists in both objects,
3185 * the provided function is applied to the key and the values associated with the key in each object,
3186 * with the result being used as the value associated with the key in the returned object.
3187 * The key will be excluded from the returned object
3188 * if the resulting value is `undefined`.
3189 *
3190 * See also {@link mergeDeepWithKey}, {@link merge}, {@link mergeWith}.
3191 *
3192 * @example
3193 * ```typescript
3194 * let concatValues = <T>(k: string, l: T, r: T) => k == 'values' ? R.concat(l as any, r as any) : r
3195 * R.mergeWithKey(concatValues,
3196 * { a: true, thing: 'foo', values: [10, 20] },
3197 * { b: true, thing: 'bar', values: [15, 35] });
3198 * //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }
3199 * ```
3200 */
3201export function mergeWithKey<U, V>(fn: (str: string, x: any, z: any) => any, a: U, b: V): any;
3202export function mergeWithKey<U>(fn: (str: string, x: any, z: any) => any, a: U): <V>(b: V) => any;
3203export function mergeWithKey(fn: (str: string, x: any, z: any) => any): <U, V>(a: U, b: V) => any;
3204
3205/**
3206 * Returns the smaller of its two arguments.
3207 *
3208 * See also {@link minBy}, {@link max}.
3209 *
3210 * @example
3211 * ```typescript
3212 * R.min(789, 123); //=> 123
3213 * R.min('a', 'b'); //=> 'a'
3214 * ```
3215 */
3216export function min<T extends Ord>(a: T, b: T): T;
3217export function min<T extends Ord>(a: T): (b: T) => T;
3218
3219/**
3220 * Takes a function and two values,
3221 * and returns whichever value produces the smaller result
3222 * when passed to the provided function.
3223 *
3224 * See also {@link min}, {@link maxBy}.
3225 *
3226 * @example
3227 * ```typescript
3228 * // square :: Number -> Number
3229 * const square = (n: number) => n * n;
3230 *
3231 * R.minBy(square, -3, 2); //=> 2
3232 *
3233 * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1
3234 * R.reduce(R.minBy(square), Infinity, [] as number); //=> Infinity
3235 * ```
3236 */
3237export function minBy<T>(keyFn: (a: T) => Ord, a: T, b: T): T;
3238export function minBy<T>(keyFn: (a: T) => Ord, a: T): (b: T) => T;
3239export function minBy<T>(keyFn: (a: T) => Ord): _.F.Curry<(a: T, b: T) => T>;
3240
3241/**
3242 * Returns the modulo of two numbers. Equivalent to `a % b` but curried.
3243 *
3244 * Divides the first parameter by the second and returns the remainder.
3245 * Note that this function preserves the JavaScript-style behavior for modulo.
3246 * For mathematical modulo see `R.mathMod`.
3247 *
3248 * See also {@link mathMod}.
3249 *
3250 * @example
3251 * ```typescript
3252 * R.modulo(17, 3); //=> 2
3253 * // JS behavior:
3254 * R.modulo(-17, 3); //=> -2
3255 * R.modulo(17, -3); //=> 2
3256 *
3257 * const isOdd = R.modulo(R.__, 2);
3258 * isOdd(42); //=> 0
3259 * isOdd(21); //=> 1
3260 * ```
3261 */
3262export function modulo(__: Placeholder, b: number): (a: number) => number;
3263export function modulo(__: Placeholder): (b: number, a: number) => number;
3264export function modulo(a: number, b: number): number;
3265export function modulo(a: number): (b: number) => number;
3266
3267/**
3268 * Returns a copy of the given list
3269 * with the item at the given source index moved to the given destination index.
3270 *
3271 * @example
3272 * ```typescript
3273 * R.move(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['b', 'c', 'a', 'd', 'e', 'f']
3274 * R.move(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'a', 'b', 'c', 'd', 'e'] list rotation
3275 * ```
3276 */
3277export function move<T>(from: number, to: number, list: readonly T[]): T[];
3278export function move(from: number, to: number): <T>(list: readonly T[]) => T[];
3279export function move(from: number): {
3280 <T>(to: number, list: readonly T[]): T[];
3281 (to: number): <T>(list: readonly T[]) => T[];
3282};
3283
3284/**
3285 * Multiplies two numbers. Equivalent to `a * b` but curried.
3286 *
3287 * See also {@link divide}.
3288 *
3289 * @example
3290 * ```typescript
3291 * const double = R.multiply(2);
3292 * const triple = R.multiply(3);
3293 * double(3); //=> 6
3294 * triple(4); //=> 12
3295 * R.multiply(2, 5); //=> 10
3296 * ```
3297 */
3298export function multiply(a: number, b: number): number;
3299export function multiply(a: number): (b: number) => number;
3300
3301/**
3302 * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters.
3303 * Any extraneous parameters will not be passed to the supplied function.
3304 *
3305 * See also {@link binary}, {@link unary}.
3306 *
3307 * @example
3308 * ```typescript
3309 * const takesTwoArgs = <T, U>(a: T, b: U) => [a, b];
3310 *
3311 * takesTwoArgs.length; //=> 2
3312 * takesTwoArgs(1, 2); //=> [1, 2]
3313 *
3314 * const takesOneArg = R.nAry(1, takesTwoArgs);
3315 * takesOneArg.length; //=> 1
3316 * // Only `n` arguments are passed to the wrapped function
3317 * takesOneArg(1); //=> [1, undefined]
3318 * ```
3319 */
3320export function nAry<N extends number, T extends AnyFunction>(
3321 n: N,
3322 fn: T,
3323): (...arg: _.T.Take<Parameters<T>, _.N.NumberOf<N>>) => ReturnType<T>;
3324export function nAry<N extends number>(
3325 n: N,
3326): <T extends AnyFunction>(fn: T) => (...arg: _.T.Take<Parameters<T>, _.N.NumberOf<N>>) => ReturnType<T>;
3327
3328/**
3329 * Negates its argument.
3330 *
3331 * @example
3332 * ```typescript
3333 * R.negate(42); //=> -42
3334 * ```
3335 */
3336export function negate(n: number): number;
3337
3338/**
3339 * Returns `true` if no elements of the list match the predicate, `false` otherwise.
3340 *
3341 * Dispatches to the `all` method of the second argument, if present.
3342 *
3343 * Acts as a transducer if a transformer is given in list position.
3344 *
3345 * See also {@link all}, {@link any}, {@link transduce}.
3346 *
3347 * @example
3348 * ```typescript
3349 * const isEven = (n: number) => n % 2 === 0;
3350 * const isOdd = (n: number) => n % 2 !== 0;
3351 *
3352 * R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true
3353 * R.none(isOdd, [1, 3, 5, 7, 8, 11]); //=> false
3354 * ```
3355 */
3356export function none<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
3357export function none<T>(fn: (a: T) => boolean): (list: readonly T[]) => boolean;
3358
3359/**
3360 * A function that returns the `!` of its argument.
3361 * It will return true when passed falsy value, and false when passed a truthy one.
3362 *
3363 * See also {@link complement}.
3364 *
3365 * @example
3366 * ```typescript
3367 * R.not(true); //=> false
3368 * R.not(false); //=> true
3369 * R.not(0); //=> true
3370 * R.not(1); //=> false
3371 * ```
3372 */
3373export function not(value: any): boolean;
3374
3375/**
3376 * Returns the nth element of the given list or string.
3377 *
3378 * If `n` is negative the element at index `length + n` is returned.
3379 *
3380 * @example
3381 * ```typescript
3382 * const list = ['foo', 'bar', 'baz', 'quux'];
3383 * R.nth(1, list); //=> 'bar'
3384 * R.nth(-1, list); //=> 'quux'
3385 * R.nth(-99, list); //=> undefined
3386 *
3387 * R.nth(2, 'abc'); //=> 'c'
3388 * R.nth(3, 'abc'); //=> ''
3389 * ```
3390 */
3391export function nth<T>(n: number, list: readonly T[]): T | undefined;
3392export function nth(n: number, list: string): string;
3393export function nth(
3394 n: number,
3395): <T extends readonly any[] | string>(list: T) => (T extends Array<infer E> ? E : string) | undefined;
3396
3397/**
3398 * Returns a function which returns its nth argument.
3399 *
3400 * @example
3401 * ```typescript
3402 * R.nthArg(1)('a', 'b', 'c'); //=> 'b'
3403 * R.nthArg(-1)('a', 'b', 'c'); //=> 'c'
3404 * ```
3405 */
3406export function nthArg(n: number): (...args: unknown[]) => unknown;
3407
3408/**
3409 * `o` is a curried composition function that returns a unary function.
3410 * Like `compose`, `o` performs right-to-left function composition.
3411 * Unlike `compose`, the rightmost function passed to `o` will be invoked with only one argument.
3412 * Also, unlike compose, `o` is limited to accepting only 2 unary functions.
3413 * The name `o` was chosen because of its similarity to the mathematical composition operator `∘`.
3414 *
3415 * See also {@link compose}, {@link pipe}.
3416 *
3417 * @example
3418 * ```typescript
3419 * type Name = { first: string; last: string; };
3420 *
3421 * const classyGreeting = (name: Name) => "The name's " + name.last + ", " + name.first + " " + name.last
3422 * const yellGreeting = R.o(R.toUpper, classyGreeting);
3423 * yellGreeting({first: 'James', last: 'Bond'}); //=> "THE NAME'S BOND, JAMES BOND"
3424 *
3425 * R.o(R.multiply(10), R.add(10))(-4) //=> 60
3426 * ```
3427 */
3428export function o<T1, T2, R>(f: (x: T2) => R, g: (x: T1) => T2, v: T1): R;
3429export function o<T1, T2, R>(f: (x: T2) => R, g: (x: T1) => T2): (v: T1) => R;
3430export function o<T2, R>(
3431 f: (x: T2) => R,
3432): {
3433 <T1>(g: (x: T1) => T2, v: T1): R;
3434 <T1>(g: (x: T1) => T2): (v: T1) => R;
3435};
3436
3437/**
3438 * Creates an object containing a single key:value pair.
3439 *
3440 * See also {@link pair}.
3441 *
3442 * @example
3443 * ```typescript
3444 * const matchPhrases = R.compose(
3445 * R.objOf('must'),
3446 * R.map(R.objOf('match_phrase'))
3447 * );
3448 * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}
3449 * ```
3450 */
3451export function objOf<T, K extends string>(key: K, value: T): Record<K, T>;
3452export function objOf<K extends string>(key: K): <T>(value: T) => Record<K, T>;
3453
3454/**
3455 * Returns a singleton array containing the value provided.
3456 *
3457 * @note This `of` is different from the ES6 `Array.of`.
3458 *
3459 * @example
3460 * ```typescript
3461 * R.of(null); //=> [null]
3462 * R.of([42]); //=> [[42]]
3463 * ```
3464 */
3465export function of<T>(x: T): T[];
3466
3467/**
3468 * Returns a partial copy of an object omitting the keys specified.
3469 *
3470 * See also {@link pick}.
3471 *
3472 * @example
3473 * ```typescript
3474 * R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
3475 * ```
3476 */
3477export function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>;
3478export function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>;
3479
3480/**
3481 * Takes a binary function `f`, a unary function `g`, and two values.
3482 * Applies `g` to each value, then applies the result of each to `f`.
3483 * Also known as the P combinator.
3484 *
3485 * @example
3486 * ```typescript
3487 * const eqBy = R.on((a, b) => a === b);
3488 * eqBy(R.prop('a'), {b:0, a:1}, {a:1}) //=> true;
3489 *
3490 * const containsInsensitive = R.on(R.contains, R.toLower);
3491 * containsInsensitive('o', 'FOO'); //=> true
3492 * ```
3493 */
3494export function on<T, U, R>(combine: (a: U, b: U) => R, transform: (value: T) => U, a: T, b: T): R;
3495export function on<T, U, R>(combine: (a: U, b: U) => R, transform: (value: T) => U, a: T): (b: T) => R;
3496export function on<T, U, R>(
3497 combine: (a: U, b: U) => R,
3498 transform: (value: T) => U,
3499): {
3500 (a: T, b: T): R;
3501 (a: T): (b: T) => R;
3502};
3503export function on<U, R>(
3504 combine: (a: U, b: U) => R,
3505): {
3506 <T>(transform: (value: T) => U, a: T, b: T): R;
3507 <T>(transform: (value: T) => U, a: T): (b: T) => R;
3508 <T>(transform: (value: T) => U): {
3509 (a: T, b: T): R;
3510 (a: T): (b: T) => R;
3511 };
3512};
3513// For manually specifying overloads
3514export function on<T, U, R>(
3515 combine: (a: U, b: U) => R,
3516): {
3517 (transform: (value: T) => U, a: T, b: T): R;
3518 (transform: (value: T) => U, a: T): (b: T) => R;
3519 (transform: (value: T) => U): {
3520 (a: T, b: T): R;
3521 (a: T): (b: T) => R;
3522 };
3523};
3524
3525/**
3526 * Accepts a function `fn` and returns a function that guards invocation of `fn`
3527 * such that `fn` can only ever be called once,
3528 * no matter how many times the returned function is invoked.
3529 * The first value calculated is returned in subsequent invocations.
3530 *
3531 * @example
3532 * ```typescript
3533 * const addOneOnce = R.once((x: number) => x + 1);
3534 * addOneOnce(10); //=> 11
3535 * addOneOnce(addOneOnce(50)); //=> 11
3536 * ```
3537 */
3538export function once<F extends AnyFunction>(fn: F): F;
3539
3540/**
3541 * Returns the first argument if it is truthy, otherwise the second argument.
3542 *
3543 * Acts as boolean `or` if both inputs are booleans.
3544 *
3545 * @note This is **not** short-circuited, meaning that if expressions are passed they are both evaluated.
3546 *
3547 * See also {@link either}, {@link and}, {@link xor}.
3548 *
3549 * @example
3550 * ```typescript
3551 * R.or(true, true); //=> true
3552 * R.or(true, false); //=> true
3553 * R.or(false, true); //=> true
3554 * R.or(false, false); //=> false
3555 * ```
3556 */
3557export function or<T, U>(a: T | Falsy, b: U): T | U;
3558export function or<T>(a: T | Falsy): <U>(b: U) => T | U;
3559
3560/**
3561 * Returns the result of applying the `onFailure` function to the value inside a failed `Promise`.
3562 * This is useful for handling rejected `Promise`s inside function compositions.
3563 *
3564 * @example
3565 * ```typescript
3566 * const failedFetch = (id: number) => Promise.reject('bad ID');
3567 * const useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' });
3568 *
3569 * //recoverFromFailure :: String -> Promise ({ firstName, lastName })
3570 * const recoverFromFailure = R.pipe(
3571 * failedFetch,
3572 * R.otherwise(useDefault),
3573 * R.andThen(R.pick(['firstName', 'lastName'])),
3574 * );
3575 * recoverFromFailure(12345).then(console.log);
3576 * ```
3577 */
3578export function otherwise<A, B>(onError: (error: any) => B | Promise<B>, promise: Promise<A>): Promise<B>;
3579export function otherwise<A, B>(onError: (error: any) => B | Promise<B>): (promise: Promise<A>) => Promise<B>;
3580
3581/**
3582 * Returns the result of "setting" the portion of the given data structure
3583 * focused by the given lens to the given value.
3584 *
3585 * See also {@link view}, {@link set}, {@link lens}, {@link lensIndex}, {@link lensProp}, {@link lensPath}.
3586 *
3587 * @example
3588 * ```typescript
3589 * const headLens = R.lensIndex<string>(0);
3590 *
3591 * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz']
3592 * ```
3593 */
3594export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;
3595export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
3596export function over<S, A>(lens: Lens<S, A>): (fn: (a: A) => A, value: S) => S;
3597
3598/**
3599 * Takes two arguments, `fst` and `snd`, and returns `[fst, snd]`.
3600 *
3601 * See also {@link objOf}, {@link of}.
3602 *
3603 * @example
3604 * ```typescript
3605 * R.pair('foo', 'bar'); //=> ['foo', 'bar']
3606 * ```
3607 */
3608export function pair<F, S>(fst: F, snd: S): [F, S];
3609export function pair<F>(fst: F): <S>(snd: S) => [F, S];
3610
3611/**
3612 * Takes a function `f` and a list of arguments, and returns a function `g`.
3613 * When applied, `g` returns the result of applying `f` to the arguments provided initially
3614 * followed by the arguments provided to `g`.
3615 *
3616 * See also {@link partialRight}, {@link curry}.
3617 *
3618 * @example
3619 * ```typescript
3620 * const multiply2 = (a: number, b: number) => a * b;
3621 * const double = R.partial(multiply2, [2]);
3622 * double(3); //=> 6
3623 *
3624 * const greet = (salutation: string, title: string, firstName: string, lastName: string) =>
3625 * salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
3626 *
3627 * const sayHello = R.partial(greet, ['Hello']);
3628 * const sayHelloToMs = R.partial(sayHello, ['Ms.']);
3629 * sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!'
3630 * ```
3631 */
3632export function partial<V0, V1, T>(fn: (x0: V0, x1: V1) => T, args: [V0]): (x1: V1) => T;
3633export function partial<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0, V1]): (x2: V2) => T;
3634export function partial<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0]): (x1: V1, x2: V2) => T;
3635export function partial<V0, V1, V2, V3, T>(
3636 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3637 args: [V0, V1, V2],
3638): (x2: V3) => T;
3639export function partial<V0, V1, V2, V3, T>(
3640 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3641 args: [V0, V1],
3642): (x2: V2, x3: V3) => T;
3643export function partial<V0, V1, V2, V3, T>(
3644 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3645 args: [V0],
3646): (x1: V1, x2: V2, x3: V3) => T;
3647
3648export function partial<T>(fn: (...args: any[]) => T, args: unknown[]): (...args: unknown[]) => T;
3649
3650/**
3651 * Takes a function `f` and an object, and returns a function `g`.
3652 * When applied, `g` returns the result of applying `f` to the object
3653 * provided initially merged deeply (right) with the object provided as an argument to `g`.
3654 *
3655 * See also {@link partial}, {@link partialRight}, {@link curry}, {@link mergeDeepRight}.
3656 *
3657 * @example
3658 * ```typescript
3659 * const multiply2 = ({ a, b }: { a: number, b: number }) => a * b;
3660 * const double = R.partialObject(multiply2, { a: 2 });
3661 * double({ b: 2 }); //=> 4
3662 *
3663 * type GreetArgs = {
3664 * salutation: string;
3665 * title: string;
3666 * firstName: string;
3667 * lastName: string;
3668 * };
3669 *
3670 * const greet = ({ salutation, title, firstName, lastName }: GreetArgs) =>
3671 * salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
3672 *
3673 * const sayHello = R.partialObject(greet, { salutation: 'Hello' });
3674 * const sayHelloToMs = R.partialObject(sayHello, { title: 'Ms.' });
3675 * sayHelloToMs({ firstName: 'Jane', lastName: 'Jones' }); //=> 'Hello, Ms. Jane Jones!'
3676 * ```
3677 */
3678// NOTE: The objects are merged deeply - meaning this should be `DeepOmit` (ideally `& Partial<Omitted>` too)
3679export function partialObject<T extends P1, P1, R>(fn: (value: T) => R, partial: P1): (value: Omit<T, keyof P1>) => R;
3680export function partialObject<T, R>(fn: (value: T) => R): <P1>(partial: P1) => (value: Omit<T, keyof P1>) => R;
3681
3682/**
3683 * Takes a function `f` and a list of arguments, and returns a function `g`.
3684 * When applied, `g` returns the result of applying `f` to the arguments
3685 * provided to `g` followed by the arguments provided initially.
3686 *
3687 * See also {@link partial}.
3688 *
3689 * @example
3690 * ```typescript
3691 * const greet = (salutation: string, title: string, firstName: string, lastName: string) =>
3692 * salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
3693 *
3694 * const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']);
3695 *
3696 * greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!'
3697 * ```
3698 */
3699export function partialRight<V0, V1, T>(fn: (x0: V0, x1: V1) => T, args: [V1]): (x1: V0) => T;
3700export function partialRight<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V1, V2]): (x2: V0) => T;
3701export function partialRight<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V2]): (x1: V0, x2: V1) => T;
3702export function partialRight<V0, V1, V2, V3, T>(
3703 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3704 args: [V1, V2, V3],
3705): (x0: V0) => T;
3706export function partialRight<V0, V1, V2, V3, T>(
3707 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3708 args: [V2, V3],
3709): (x0: V0, x1: V1) => T;
3710export function partialRight<V0, V1, V2, V3, T>(
3711 fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T,
3712 args: [V3],
3713): (x0: V0, x1: V1, x2: V2) => T;
3714
3715export function partialRight<T>(fn: (...args: any[]) => T, args: unknown[]): (...args: unknown[]) => T;
3716
3717/**
3718 * Takes a predicate and a list or other `Filterable` object
3719 * and returns the elements split into two lists
3720 * based on whether the element satisfied the predicate.
3721 * Filterable objects include plain objects
3722 * and objects with a `filter` method such as `Array`.
3723 *
3724 * See also {@link filter}, {@link reject}.
3725 *
3726 * @example
3727 * ```typescript
3728 * R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']);
3729 * // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ]
3730 *
3731 * R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' });
3732 * // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ]
3733 * ```
3734 */
3735export function partition(fn: (a: string) => boolean, list: readonly string[]): [string[], string[]];
3736export function partition<T>(fn: (a: T) => boolean, list: readonly T[]): [T[], T[]];
3737export function partition<T>(fn: (a: T) => boolean): (list: readonly T[]) => [T[], T[]];
3738export function partition(fn: (a: string) => boolean): (list: readonly string[]) => [string[], string[]];
3739
3740/**
3741 * Retrieve the value at a given path.
3742 *
3743 * See also {@link prop}, {@link nth}.
3744 *
3745 * @example
3746 * ```typescript
3747 * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
3748 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
3749 * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1
3750 * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2
3751 * ```
3752 */
3753export function path<S, K0 extends keyof S = keyof S>(path: [K0], obj: S): S[K0];
3754export function path<S, K0 extends keyof S = keyof S, K1 extends keyof S[K0] = keyof S[K0]>(path: [K0, K1], obj: S): S[K0][K1];
3755export function path<
3756 S,
3757 K0 extends keyof S = keyof S,
3758 K1 extends keyof S[K0] = keyof S[K0],
3759 K2 extends keyof S[K0][K1] = keyof S[K0][K1]
3760>(path: [K0, K1, K2], obj: S): S[K0][K1][K2];
3761export function path<
3762 S,
3763 K0 extends keyof S = keyof S,
3764 K1 extends keyof S[K0] = keyof S[K0],
3765 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
3766 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
3767>(path: [K0, K1, K2, K3], obj: S): S[K0][K1][K2][K3];
3768export function path<
3769 S,
3770 K0 extends keyof S = keyof S,
3771 K1 extends keyof S[K0] = keyof S[K0],
3772 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
3773 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
3774 K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
3775>(path: [K0, K1, K2, K3, K4], obj: S): S[K0][K1][K2][K3][K4];
3776export function path<
3777 S,
3778 K0 extends keyof S = keyof S,
3779 K1 extends keyof S[K0] = keyof S[K0],
3780 K2 extends keyof S[K0][K1] = keyof S[K0][K1],
3781 K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
3782 K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
3783 K5 extends keyof S[K0][K1][K2][K3][K4] = keyof S[K0][K1][K2][K3][K4],
3784>(path: [K0, K1, K2, K3, K4, K5], obj: S): S[K0][K1][K2][K3][K4][K5];
3785export function path<T>(path: Path, obj: any): T | undefined;
3786export function path<T>(path: Path): (obj: any) => T | undefined;
3787
3788/**
3789 * Determines whether a nested path on an object has a specific value,
3790 * in {@link equals `R.equals`} terms.
3791 * Most likely used to filter a list.
3792 *
3793 * @example
3794 * ```typescript
3795 * const user1 = { address: { zipCode: 90210 } };
3796 * const user2 = { address: { zipCode: 55555 } };
3797 * const user3 = { name: 'Bob' };
3798 * const users = [ user1, user2, user3 ];
3799 * const isFamous = R.pathEq(['address', 'zipCode'], 90210);
3800 * R.filter(isFamous, users); //=> [ user1 ]
3801 * ```
3802 */
3803export function pathEq(path: Path, val: any, obj: any): boolean;
3804export function pathEq(path: Path, val: any): (obj: any) => boolean;
3805export function pathEq(path: Path): _.F.Curry<(a: any, b: any) => boolean>;
3806
3807/**
3808 * If the given, non-null object has a value at the given path,
3809 * returns the value at that path.
3810 * Otherwise returns the provided default value.
3811 *
3812 * @example
3813 * ```typescript
3814 * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
3815 * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
3816 * ```
3817 */
3818export function pathOr<T>(defaultValue: T, path: Path, obj: any): T;
3819export function pathOr<T>(defaultValue: T, path: Path): (obj: any) => T;
3820export function pathOr<T>(defaultValue: T): _.F.Curry<(a: Path, b: any) => T>;
3821
3822/**
3823 * Retrieves the values at given paths of an object.
3824 *
3825 * See also {@link path}.
3826 *
3827 * @example
3828 * ```typescript
3829 * R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3]
3830 * R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined]
3831 * ```
3832 */
3833export function paths<T>(paths: readonly Path[], obj: any): Array<T | undefined>;
3834export function paths<T>(paths: readonly Path[]): (obj: any) => Array<T | undefined>;
3835
3836/**
3837 * Returns `true` if the specified object property at given path satisfies the given predicate;
3838 * `false` otherwise.
3839 *
3840 * See also {@link propSatisfies}, {@link path}.
3841 *
3842 * @example
3843 * ```typescript
3844 * R.pathSatisfies((y: number) => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true
3845 * R.pathSatisfies(R.is(Object), [], {x: {y: 2}}); //=> true
3846 * ```
3847 */
3848export function pathSatisfies<T, U>(pred: (val: T) => boolean, path: Path, obj: U): boolean;
3849export function pathSatisfies<T, U>(pred: (val: T) => boolean, path: Path): (obj: U) => boolean;
3850export function pathSatisfies<T, U>(pred: (val: T) => boolean): _.F.Curry<(a: Path, b: U) => boolean>;
3851
3852/**
3853 * Returns a partial copy of an object containing only the keys specified.
3854 * If the key does not exist, the property is ignored.
3855 *
3856 * See also {@link omit}, {@link props}.
3857 *
3858 * @example
3859 * ```typescript
3860 * R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
3861 * R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
3862 * ```
3863 */
3864export function pick<T extends readonly [any, ...any], K extends string | number | symbol>(
3865 names: readonly K[],
3866 array: T,
3867): {
3868 [P in K as P extends string | number
3869 ? _.N.Greater<`${T['length']}`, `${P}`> extends 1
3870 ? P
3871 : never
3872 : never]: P extends keyof T ? T[P] : T[number];
3873};
3874export function pick<T, K extends string | number | symbol>(
3875 names: readonly K[],
3876 obj: T,
3877): { [P in keyof T as P extends K ? P : never]: T[P] };
3878export function pick<K extends string | number | symbol>(
3879 names: readonly K[],
3880): <T extends readonly [any, ...any] | object>(
3881 obj: T,
3882) => T extends readonly [any, ...any]
3883 ? {
3884 [P in K as P extends string | number
3885 ? _.N.Greater<`${T['length']}`, `${P}`> extends 1
3886 ? P
3887 : never
3888 : never]: P extends keyof T ? T[P] : T[number];
3889 }
3890 : { [P in keyof T as P extends K ? P : never]: T[P] };
3891
3892/**
3893 * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist.
3894 *
3895 * @example
3896 * ```typescript
3897 * R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
3898 * R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}
3899 * ```
3900 */
3901export function pickAll<T, K extends keyof T>(names: readonly K[], obj: T): Pick<T, K>;
3902export function pickAll<T, U>(names: readonly string[], obj: T): U;
3903export function pickAll(names: readonly string[]): <T, U>(obj: T) => U;
3904
3905/**
3906 * Returns a partial copy of an object containing only the keys that satisfy the supplied predicate.
3907 *
3908 * @example
3909 * ```typescript
3910 * const isUpperCase = <T>(_val: T, key: string) => key.toUpperCase() === key;
3911 * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
3912 * ```
3913 */
3914export function pickBy<T, U>(pred: ObjPred<T>, obj: T): U;
3915export function pickBy<T>(pred: ObjPred<T>): <U, V extends T>(obj: V) => U;
3916
3917/**
3918 * Creates a new function that runs each of the functions supplied as parameters in turn,
3919 * passing the return value of each function invocation to the next function invocation,
3920 * beginning with whatever arguments were passed to the initial invocation.
3921 *
3922 * Performs left-to-right function composition.
3923 * The first argument may have any arity; the remaining arguments must be unary.
3924 *
3925 * In some libraries this function is named `sequence`.
3926 *
3927 * @note The result of `pipe` is not automatically curried.
3928 *
3929 * See also {@link compose}.
3930 *
3931 * @example
3932 * ```typescript
3933 * const f = R.pipe(Math.pow, R.negate, R.inc);
3934 *
3935 * f(3, 4); // -(3^4) + 1
3936 * ```
3937 */
3938export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
3939 ...funcs: [
3940 f1: (...args: TArgs) => R1,
3941 f2: (a: R1) => R2,
3942 f3: (a: R2) => R3,
3943 f4: (a: R3) => R4,
3944 f5: (a: R4) => R5,
3945 f6: (a: R5) => R6,
3946 f7: (a: R6) => R7,
3947 ...func: Array<(a: any) => any>,
3948 fnLast: (a: any) => TResult,
3949 ]
3950): (...args: TArgs) => TResult; // fallback overload if number of piped functions greater than 7
3951export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
3952 f1: (...args: TArgs) => R1,
3953 f2: (a: R1) => R2,
3954 f3: (a: R2) => R3,
3955 f4: (a: R3) => R4,
3956 f5: (a: R4) => R5,
3957 f6: (a: R5) => R6,
3958 f7: (a: R6) => R7,
3959): (...args: TArgs) => R7;
3960export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
3961 f1: (...args: TArgs) => R1,
3962 f2: (a: R1) => R2,
3963 f3: (a: R2) => R3,
3964 f4: (a: R3) => R4,
3965 f5: (a: R4) => R5,
3966 f6: (a: R5) => R6,
3967): (...args: TArgs) => R6;
3968export function pipe<TArgs extends any[], R1, R2, R3, R4, R5>(
3969 f1: (...args: TArgs) => R1,
3970 f2: (a: R1) => R2,
3971 f3: (a: R2) => R3,
3972 f4: (a: R3) => R4,
3973 f5: (a: R4) => R5,
3974): (...args: TArgs) => R5;
3975export function pipe<TArgs extends any[], R1, R2, R3, R4>(
3976 f1: (...args: TArgs) => R1,
3977 f2: (a: R1) => R2,
3978 f3: (a: R2) => R3,
3979 f4: (a: R3) => R4,
3980): (...args: TArgs) => R4;
3981export function pipe<TArgs extends any[], R1, R2, R3>(
3982 f1: (...args: TArgs) => R1,
3983 f2: (a: R1) => R2,
3984 f3: (a: R2) => R3,
3985): (...args: TArgs) => R3;
3986export function pipe<TArgs extends any[], R1, R2>(
3987 f1: (...args: TArgs) => R1,
3988 f2: (a: R1) => R2,
3989): (...args: TArgs) => R2;
3990export function pipe<TArgs extends any[], R1>(f1: (...args: TArgs) => R1): (...args: TArgs) => R1;
3991
3992/**
3993 * Performs left-to-right function composition using transforming function.
3994 * The first function may have any arity; the remaining functions must be unary.
3995 *
3996 * @note The result of `pipeWith` is not automatically curried. Transforming function is not used on the first argument.
3997 *
3998 * See also {@link composeWith}, {@link pipe}.
3999 *
4000 * @example
4001 * ```typescript
4002 * const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res));
4003 * const f = pipeWhileNotNil([Math.pow, R.negate, R.inc])
4004 *
4005 * f(3, 4); // -(3^4) + 1
4006 * ```
4007 */
4008export function pipeWith<TArgs extends any[], TResult>(
4009 transformer: (fn: AnyFunction, intermediateResult: any) => any,
4010 fns: AtLeastOneFunctionsFlow<TArgs, TResult>,
4011): (...args: TArgs) => TResult;
4012export function pipeWith(
4013 transformer: (fn: AnyFunction, intermediateResult: any) => any,
4014): <TArgs extends any[], TResult>(fns: AtLeastOneFunctionsFlow<TArgs, TResult>) => (...args: TArgs) => TResult;
4015
4016/**
4017 * Returns a new list by plucking the same named property off all objects in the list supplied.
4018 *
4019 * `pluck` will work on any functor in addition to arrays, as it is equivalent to `R.map(R.prop(k), f)`.
4020 *
4021 * See also {@link project}, {@link prop}, {@link props}.
4022 *
4023 * @example
4024 * ```typescript
4025 * var getAges = R.pluck('age');
4026 * const people = [{name: 'fred', age: 29}, {name: 'wilma', age: 27}]
4027 * getAges(people); //=> [29, 27]
4028 *
4029 * R.pluck(0, [[1, 2], [3, 4]]); //=> [1, 3]
4030 * R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5}
4031 * ```
4032 */
4033export function pluck<K extends keyof T, T>(p: K, list: readonly T[]): Array<T[K]>;
4034export function pluck<T>(p: number, list: ReadonlyArray<{ [k: number]: T }>): T[];
4035export function pluck<P extends string>(p: P): <T>(list: ReadonlyArray<Record<P, T>>) => T[];
4036export function pluck(p: number): <T>(list: ReadonlyArray<{ [k: number]: T }>) => T[];
4037
4038/**
4039 * Returns a new list with the given element at the front,
4040 * followed by the contents of the list.
4041 *
4042 * See also {@link append}.
4043 *
4044 * @example
4045 * ```typescript
4046 * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']
4047 * ```
4048 */
4049export function prepend<T>(el: T, list: readonly T[]): T[];
4050export function prepend<T>(el: T): (list: readonly T[]) => T[];
4051
4052/**
4053 * Multiplies together all the elements of a list.
4054 *
4055 * See also {@link reduce}.
4056 *
4057 * @example
4058 * ```typescript
4059 * R.product([2,4,6,8,100,1]); //=> 38400
4060 * ```
4061 */
4062export function product(list: readonly number[]): number;
4063
4064/**
4065 * Reasonable analog to SQL `select` statement.
4066 *
4067 * See also {@link pluck}, {@link props}, {@link prop}.
4068 *
4069 * @example
4070 * ```typescript
4071 * const abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
4072 * const fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
4073 * const kids = [abby, fred];
4074 * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]
4075 * ```
4076 */
4077export function project<T, U>(props: readonly string[], objs: readonly T[]): U[];
4078export function project<T, U>(props: readonly string[]): (objs: readonly T[]) => U[];
4079
4080/**
4081 * Takes two functions as pre- and post- processors respectively for a third function,
4082 * i.e. `promap(f, g, h)(x) === g(h(f(x)))`.
4083 * Dispatches to the `promap` method of the third argument, if present,
4084 * according to the FantasyLand Profunctor spec.
4085 * Acts as a transducer if a transformer is given in profunctor position.
4086 *
4087 * See also {@link transduce}.
4088 *
4089 * @example
4090 * ```typescript
4091 * const decodeChar = R.promap((s: string) => s.charCodeAt(0), String.fromCharCode, R.add(-8))
4092 * const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar))
4093 * decodeString("ziuli") //=> "ramda"
4094 * ```
4095 */
4096export function promap<A, B, C, D>(pre: (value: A) => B, post: (value: C) => D, fn: (value: B) => C): (value: A) => D;
4097export function promap<A, B, C, D>(
4098 pre: (value: A) => B,
4099 post: (value: C) => D,
4100): (fn: (value: B) => C) => (value: A) => D;
4101export function promap<A, B>(
4102 pre: (value: A) => B,
4103): <C, D>(post: (value: C) => D, fn: (value: B) => C) => (value: A) => D;
4104
4105/**
4106 * Returns a function that when supplied an object
4107 * returns the indicated property of that object, if it exists.
4108 *
4109 * See also {@link propOr}, {@link path}, {@link props}, {@link pluck}, {@link project}, {@link nth}.
4110 *
4111 * @example
4112 * ```typescript
4113 * R.prop('x', {x: 100}); //=> 100
4114 * R.prop(0, [100]); //=> 100
4115 * R.compose(R.inc, R.prop<number>('x'))({ x: 3 }) //=> 4
4116 * ```
4117 */
4118export function prop<_, T>(__: Placeholder, value: T): {
4119 <P extends keyof Exclude<T, undefined>>(p: P): Prop<T, P>;
4120 <P extends keyof never>(p: P): Prop<T, P>;
4121};
4122export function prop<V>(__: Placeholder, value: unknown): (p: keyof never) => V;
4123export function prop<_, P extends keyof never, T>(p: P, value: T): Prop<T, P>;
4124export function prop<V>(p: keyof never, value: unknown): V;
4125export function prop<_, P extends keyof never>(p: P): <T>(value: T) => Prop<T, P>;
4126export function prop<V>(p: keyof never): (value: unknown) => V;
4127
4128// NOTE: `hair` property was added to `alois` to make example work.
4129// A union of two types is a valid usecase but doesn't work with current types
4130/**
4131 * Returns `true` if the specified object property is equal,
4132 * in `R.equals` terms, to the given value; `false` otherwise.
4133 * You can test multiple properties with `R.whereEq`.
4134 *
4135 * See also {@link whereEq}, {@link propSatisfies}, {@link equals}.
4136 *
4137 * @example
4138 * ```typescript
4139 * const abby = {name: 'Abby', age: 7, hair: 'blond'};
4140 * const fred = {name: 'Fred', age: 12, hair: 'brown'};
4141 * const rusty = {name: 'Rusty', age: 10, hair: 'brown'};
4142 * const alois = {name: 'Alois', age: 15, hair: 'brown', disposition: 'surly'};
4143 * const kids = [abby, fred, rusty, alois];
4144 * const hasBrownHair = R.propEq('hair', 'brown');
4145 * R.filter(hasBrownHair, kids); //=> [fred, rusty]
4146 * ```
4147 */
4148export function propEq<K extends string | number>(name: K, val: any, obj: Record<K, any>): boolean;
4149export function propEq<K extends string | number>(name: K, val: any): (obj: Record<K, any>) => boolean;
4150export function propEq<K extends string | number>(
4151 name: K,
4152): {
4153 (val: any, obj: Record<K, any>): boolean;
4154 (val: any): (obj: Record<K, any>) => boolean;
4155};
4156
4157/**
4158 * Returns `true` if the specified object property is of the given type; `false` otherwise.
4159 *
4160 * See also {@link is}, {@link propSatisfies}.
4161 *
4162 * @example
4163 * ```typescript
4164 * R.propIs(Number, 'x', {x: 1, y: 2}); //=> true
4165 * R.propIs(Number, 'x', {x: 'foo'}); //=> false
4166 * R.propIs(Number, 'x', {}); //=> false
4167 * ```
4168 */
4169export function propIs<C extends AnyFunction, K extends PropertyKey>(
4170 type: C,
4171 name: K,
4172 obj: any,
4173): obj is Record<K, ReturnType<C>>;
4174export function propIs<C extends AnyConstructor, K extends PropertyKey>(
4175 type: C,
4176 name: K,
4177 obj: any,
4178): obj is Record<K, InstanceType<C>>;
4179export function propIs<C extends AnyFunction, K extends PropertyKey>(
4180 type: C,
4181 name: K,
4182): (obj: any) => obj is Record<K, ReturnType<C>>;
4183export function propIs<C extends AnyConstructor, K extends PropertyKey>(
4184 type: C,
4185 name: K,
4186): (obj: any) => obj is Record<K, InstanceType<C>>;
4187export function propIs<C extends AnyFunction>(
4188 type: C,
4189): {
4190 <K extends keyof any>(name: K, obj: any): obj is Record<K, ReturnType<C>>;
4191 <K extends keyof any>(name: K): (obj: any) => obj is Record<K, ReturnType<C>>;
4192};
4193export function propIs<C extends AnyConstructor>(
4194 type: C,
4195): {
4196 <K extends keyof any>(name: K, obj: any): obj is Record<K, InstanceType<C>>;
4197 <K extends keyof any>(name: K): (obj: any) => obj is Record<K, InstanceType<C>>;
4198};
4199
4200/**
4201 * Return the specified property of the given non-null object
4202 * if the property is present and its value is not `null`, `undefined` or `NaN`.
4203 *
4204 * Otherwise the first argument is returned.
4205 *
4206 * See also {@link prop}.
4207 *
4208 * @example
4209 * ```typescript
4210 * const alice = {
4211 * name: 'ALICE',
4212 * age: 101
4213 * };
4214 * const favorite = R.prop('favoriteLibrary');
4215 * const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
4216 *
4217 * favorite(alice as any); //=> undefined
4218 * favoriteWithDefault(alice); //=> 'Ramda'
4219 * ```
4220 */
4221export function propOr<T, U>(val: T, __: Placeholder, obj: U): <V>(p: string) => V;
4222export function propOr<U>(__: Placeholder, p: string, obj: U): <T, V>(val: T) => V;
4223export function propOr<T, U, V>(val: T, p: string, obj: U): V;
4224export function propOr<T>(val: T, p: string): <U, V>(obj: U) => V;
4225export function propOr<T>(val: T): <U, V>(p: string, obj: U) => V;
4226
4227/**
4228 * Acts as multiple `prop`: array of keys in, array of values out. Preserves order.
4229 *
4230 * See also {@link prop}, {@link pluck}, {@link project}.
4231 *
4232 * @example
4233 * ```typescript
4234 * R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
4235 * R.props(['c', 'a', 'b'], {b: 2, a: 1, c: 3}); //=> [3, 1, 2]
4236 *
4237 * const fullName = R.compose(R.join(' '), R.props(['first', 'last']));
4238 * const tony = {last: 'Bullet-Tooth', age: 33, first: 'Tony'};
4239 * fullName(tony); //=> 'Tony Bullet-Tooth'
4240 * ```
4241 */
4242export function props<P extends string, T>(ps: readonly P[], obj: Record<P, T>): T[];
4243export function props<P extends string>(ps: readonly P[]): <T>(obj: Record<P, T>) => T[];
4244export function props<P extends string, T>(ps: readonly P[]): (obj: Record<P, T>) => T[];
4245
4246/**
4247 * Returns `true` if the specified object property satisfies the given predicate; `false` otherwise.
4248 * You can test multiple properties with `R.where`.
4249 *
4250 * See also {@link where}, {@link propEq}, {@link propIs}.
4251 *
4252 * @example
4253 * ```typescript
4254 * const val = {x: 1, y: 2};
4255 * R.propSatisfies(x => x > 0, 'x', val); //=> true
4256 * ```
4257 */
4258export function propSatisfies<P, K extends keyof any>(
4259 pred: (val: any) => val is P,
4260 name: K,
4261 obj: any,
4262): obj is Record<K, P>;
4263export function propSatisfies<P, K extends keyof any>(
4264 pred: (val: any) => val is P,
4265 name: K,
4266): (obj: any) => obj is Record<K, P>;
4267export function propSatisfies<P>(pred: (val: any) => val is P): {
4268 <K extends keyof any>(name: K, obj: any): obj is Record<K, P>;
4269 <K extends keyof any>(name: K): (obj: any) => obj is Record<K, P>;
4270};
4271export function propSatisfies(pred: (val: any) => boolean, name: keyof any, obj: any): boolean;
4272export function propSatisfies(pred: (val: any) => boolean, name: keyof any): (obj: any) => boolean;
4273export function propSatisfies(pred: (val: any) => boolean): _.F.Curry<(a: keyof any, b: any) => boolean>;
4274
4275/**
4276 * Returns a list of numbers from `from` (inclusive) to `to` (exclusive).
4277 * In mathematical terms, `range(a, b)` is equivalent to the half-open interval `[a, b)`.
4278 *
4279 * @example
4280 * ```typescript
4281 * R.range(1, 5); //=> [1, 2, 3, 4]
4282 * R.range(50, 53); //=> [50, 51, 52]
4283 * ```
4284 */
4285export function range(from: number, to: number): number[];
4286export function range(from: number): (to: number) => number[];
4287
4288/**
4289 * Returns a single item by iterating through the list,
4290 * successively calling the iterator function and passing it an accumulator value and the current value from the array,
4291 * and then passing the result to the next call.
4292 *
4293 * The iterator function receives two values: `(acc, value)`. It may use `R.reduced` to shortcut the iteration.
4294 *
4295 * @note `R.reduce` does not skip deleted or unassigned indices (sparse arrays), unlike the native `Array.prototype.reduce` method.
4296 *
4297 * Dispatches to the `reduce` method of the third argument, if present.
4298 * When doing so, it is up to the user to handle the `R.reduced` shortcutting,
4299 * as this is not implemented by `reduce`.
4300 *
4301 * See also {@link reduced}, {@link addIndex}, {@link reduceRight}.
4302 *
4303 * @example
4304 * ```typescript
4305 * R.reduce(R.subtract, 0, [1, 2, 3, 4]) //=> ((((0 - 1) - 2) - 3) - 4) = -10
4306 * // - -10
4307 * // / \ / \
4308 * // - 4 -6 4
4309 * // / \ / \
4310 * // - 3 ==> -3 3
4311 * // / \ / \
4312 * // - 2 -1 2
4313 * // / \ / \
4314 * // 0 1 0 1
4315 * ```
4316 */
4317export function reduce<T, TResult>(
4318 fn: (acc: TResult, elem: T) => TResult | Reduced<TResult>,
4319 acc: TResult,
4320 list: readonly T[],
4321): TResult;
4322export function reduce<T, TResult>(
4323 fn: (acc: TResult, elem: T) => TResult | Reduced<TResult>,
4324): (acc: TResult, list: readonly T[]) => TResult;
4325export function reduce<T, TResult>(
4326 fn: (acc: TResult, elem: T) => TResult | Reduced<TResult>,
4327 acc: TResult,
4328): (list: readonly T[]) => TResult;
4329
4330/**
4331 * Groups the elements of the list
4332 * according to the result of calling the string-returning function `keyFn` on each element
4333 * and reduces the elements of each group to a single value via the reducer function `valueFn`.
4334 *
4335 * The value function receives two values: `(acc, value)`.
4336 * It may use `R.reduced` to short circuit the iteration.
4337 *
4338 * This function is basically a more general `R.groupBy` function.
4339 *
4340 * Acts as a transducer if a transformer is given in list position.
4341 *
4342 * See also {@link groupBy}, {@link reduce}, {@link reduced}, {@link transduce}.
4343 *
4344 * @example
4345 * ```typescript
4346 * const groupNames = (acc: string[], { name }: { name: string; }) => acc.concat(name)
4347 * const toGrade = ({ score }: { score: number; }) =>
4348 * score < 65 ? 'F' :
4349 * score < 70 ? 'D' :
4350 * score < 80 ? 'C' :
4351 * score < 90 ? 'B' : 'A'
4352 *
4353 * var students = [
4354 * {name: 'Abby', score: 83},
4355 * {name: 'Bart', score: 62},
4356 * {name: 'Curt', score: 88},
4357 * {name: 'Dora', score: 92},
4358 * ]
4359 *
4360 * R.reduceBy(groupNames, [], toGrade, students)
4361 * //=> {"A": ["Dora"], "B": ["Abby", "Curt"], "F": ["Bart"]}
4362 * ```
4363 */
4364export function reduceBy<T, TResult>(
4365 valueFn: (acc: TResult, elem: T) => TResult,
4366 acc: TResult,
4367 keyFn: (elem: T) => string,
4368 list: readonly T[],
4369): { [index: string]: TResult };
4370export function reduceBy<T, TResult>(
4371 valueFn: (acc: TResult, elem: T) => TResult,
4372 acc: TResult,
4373 keyFn: (elem: T) => string,
4374): (list: readonly T[]) => { [index: string]: TResult };
4375export function reduceBy<T, TResult>(
4376 valueFn: (acc: TResult, elem: T) => TResult,
4377 acc: TResult,
4378): _.F.Curry<(a: (elem: T) => string, b: readonly T[]) => { [index: string]: TResult }>;
4379export function reduceBy<T, TResult>(
4380 valueFn: (acc: TResult, elem: T) => TResult,
4381): _.F.Curry<(a: TResult, b: (elem: T) => string, c: readonly T[]) => { [index: string]: TResult }>;
4382
4383/**
4384 * Returns a value wrapped to indicate that it is the final value of the `R.reduce` and `R.transduce` functions.
4385 * The returned value should be considered a black box:
4386 * the internal structure is not guaranteed to be stable.
4387 *
4388 * This optimization is available to the below functions:
4389 * - `R.reduce`
4390 * - `R.reduceWhile`
4391 * - `R.reduceBy`
4392 * - `R.reduceRight`
4393 * - `R.transduce`
4394 *
4395 * See also {@link reduce}, {@link reduceWhile}, {@link reduceBy}, {@link reduceRight}, {@link transduce}.
4396 *
4397 * @example
4398 * ```typescript
4399 * R.reduce(
4400 * (acc, item) => item > 3 ? R.reduced(acc) : acc.concat(item),
4401 * [] as number[],
4402 * [1, 2, 3, 4, 5]) // [1, 2, 3]
4403 * ```
4404 */
4405export function reduced<T>(elem: T): Reduced<T>;
4406
4407// NOTE: the example currently does not work, even if `R.__` overloads are removed
4408/**
4409 * Returns a single item by iterating through the list,
4410 * successively calling the iterator function
4411 * and passing it an accumulator value and the current value from the array,
4412 * and then passing the result to the next call.
4413 *
4414 * Similar to `R.reduce`, except moves through the input list from the right to the left.
4415 *
4416 * The iterator function receives two values: `(value, acc)`,
4417 * reversed compared to that of `R.reduce`'s iterator function.
4418 * `reduceRight` may use `R.reduced` to short circuit the iteration.
4419 *
4420 * @note `R.reduceRight` does not skip deleted or unassigned indices (sparse arrays),
4421 * unlike the native `Array.prototype.reduceRight` method.
4422 *
4423 * See also {@link reduce}, {@link addIndex}, {@link reduced}.
4424 *
4425 * @example
4426 * ```typescript
4427 * R.reduceRight(R.subtract, 0, [1, 2, 3, 4]) // => (1 - (2 - (3 - (4 - 0)))) = -2
4428 * // - -2
4429 * // / \ / \
4430 * // 1 - 1 3
4431 * // / \ / \
4432 * // 2 - ==> 2 -1
4433 * // / \ / \
4434 * // 3 - 3 4
4435 * // / \ / \
4436 * // 4 0 4 0
4437 * ```
4438 */
4439export function reduceRight<T, TResult>(
4440 fn: (elem: T, acc: TResult) => TResult,
4441 acc: TResult,
4442 list: readonly T[],
4443): TResult;
4444export function reduceRight<T, TResult>(
4445 fn: (elem: T, acc: TResult) => TResult,
4446): (acc: TResult, list: readonly T[]) => TResult;
4447export function reduceRight<T, TResult>(
4448 fn: (elem: T, acc: TResult) => TResult,
4449 acc: TResult,
4450): (list: readonly T[]) => TResult;
4451
4452/**
4453 * Like `R.reduce`, `R.reduceWhile` returns a single item by iterating through the list,
4454 * successively calling the iterator function.
4455 * `R.reduceWhile` also takes a predicate that is evaluated before each step.
4456 * If the predicate returns a falsy value,
4457 * it "short-circuits" the iteration and returns the current value of the accumulator.
4458 *
4459 * See also {@link reduce}, {@link reduced}.
4460 *
4461 * @example
4462 * ```typescript
4463 * const isOdd = (acc: number, x: number) => x % 2 !== 0;
4464 * const xs = [1, 3, 5, 60, 777, 800];
4465 * R.reduceWhile(isOdd, R.add, 0, xs); //=> 9
4466 *
4467 * const ys = [2, 4, 6]
4468 * R.reduceWhile(isOdd, R.add, 111, ys); //=> 111
4469 * ```
4470 */
4471export function reduceWhile<T, TResult>(
4472 predicate: (acc: TResult, elem: T) => boolean,
4473 fn: (acc: TResult, elem: T) => TResult,
4474 acc: TResult,
4475 list: readonly T[],
4476): TResult;
4477export function reduceWhile<T, TResult>(
4478 predicate: (acc: TResult, elem: T) => boolean,
4479 fn: (acc: TResult, elem: T) => TResult,
4480 acc: TResult,
4481): (list: readonly T[]) => TResult;
4482export function reduceWhile<T, TResult>(
4483 predicate: (acc: TResult, elem: T) => boolean,
4484 fn: (acc: TResult, elem: T) => TResult,
4485): _.F.Curry<(a: TResult, b: readonly T[]) => TResult>;
4486export function reduceWhile<T, TResult>(
4487 predicate: (acc: TResult, elem: T) => boolean,
4488): _.F.Curry<(a: (acc: TResult, elem: T) => TResult, b: TResult, c: readonly T[]) => TResult>;
4489
4490/**
4491 * The complement of `R.filter`.
4492 *
4493 * Acts as a transducer if a transformer is given in list position.
4494 * `Filterable` objects include plain objects or any object that has a `filter` method such as `Array`.
4495 *
4496 * See also {@link filter}, {@link transduce}, {@link addIndex}.
4497 *
4498 * @example
4499 * ```typescript
4500 * const isOdd = (n: number) => n % 2 !== 0;
4501 *
4502 * R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
4503 *
4504 * R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}
4505 * ```
4506 */
4507export function reject<A, P extends A>(
4508 pred: (val: A) => val is P,
4509): {
4510 <B extends A>(list: readonly B[]): Array<Exclude<B, P>>;
4511 <B extends A>(dict: Dictionary<B>): Dictionary<Exclude<B, P>>;
4512};
4513export function reject<T>(
4514 pred: (value: T) => boolean,
4515): <P extends T, C extends readonly P[] | Dictionary<P>>(collection: C) => C;
4516export function reject<A, B extends A, P extends A>(
4517 pred: (val: A) => val is P,
4518 list: readonly B[],
4519): Array<Exclude<B, P>>;
4520export function reject<A, B extends A, P extends A>(
4521 pred: (val: A) => val is P,
4522 dict: Dictionary<B>,
4523): Dictionary<Exclude<B, P>>;
4524export function reject<T, C extends readonly T[] | Dictionary<T>>(pred: (value: T) => boolean, collection: C): C;
4525
4526/**
4527 * Returns a copy of the given list
4528 * with the given number of elements removed,
4529 * starting at the given start index.
4530 *
4531 * See also {@link without}.
4532 *
4533 * @example
4534 * ```typescript
4535 * R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]
4536 * ```
4537 */
4538export function remove<T>(start: number, count: number, list: readonly T[]): T[];
4539export function remove<T>(start: number): {
4540 (count: number, list: readonly T[]): T[];
4541 (count: number): (list: readonly T[]) => T[];
4542};
4543export function remove<T>(start: number, count: number): (list: readonly T[]) => T[];
4544
4545/**
4546 * Returns a fixed list of size `n`, containing a specified identical value.
4547 *
4548 * See also {@link times}.
4549 *
4550 * @example
4551 * ```typescript
4552 * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
4553 *
4554 * const obj = {};
4555 * const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
4556 * repeatedObjs[0] === repeatedObjs[1]; //=> true
4557 * ```
4558 */
4559export function repeat<T>(a: T, n: number): T[];
4560export function repeat<T>(a: T): (n: number) => T[];
4561
4562/**
4563 * Replace a substring or regex match in a string with a replacement.
4564 *
4565 * The first two parameters correspond to the parameters of `String.prototype.replace`,
4566 * so the second parameter can also be a function.
4567 *
4568 * @example
4569 * ```typescript
4570 * R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
4571 * R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
4572 *
4573 * // Use the "g" (global) flag to replace all occurrences:
4574 * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'
4575 * ```
4576 */
4577export function replace(
4578 pattern: RegExp | string,
4579 replacement: string | ((match: string, ...args: readonly any[]) => string),
4580 str: string,
4581): string;
4582export function replace(
4583 pattern: RegExp | string,
4584 replacement: string | ((match: string, ...args: readonly any[]) => string),
4585): (str: string) => string;
4586export function replace(
4587 pattern: RegExp | string,
4588): (replacement: string | ((match: string, ...args: readonly any[]) => string)) => (str: string) => string;
4589
4590/**
4591 * Returns a new list or string with the elements in reverse order.
4592 *
4593 * @example
4594 * ```typescript
4595 * R.reverse([1, 2, 3]); //=> [3, 2, 1]
4596 * R.reverse([1, 2]); //=> [2, 1]
4597 * R.reverse([1]); //=> [1]
4598 * R.reverse([]); //=> []
4599 *
4600 * R.reverse('abc'); //=> 'cba'
4601 * R.reverse('ab'); //=> 'ba'
4602 * R.reverse('a'); //=> 'a'
4603 * R.reverse(''); //=> ''
4604 * ```
4605 */
4606export function reverse<T>(list: readonly T[]): T[];
4607export function reverse(str: string): string;
4608
4609/**
4610 * Similar to `R.reduce`, but returns a list of successively reduced values from the left.
4611 *
4612 * See also {@link reduce}, {@link mapAccum}.
4613 *
4614 * @example
4615 * ```typescript
4616 * const numbers = [1, 2, 3, 4];
4617 * const factorials = R.scan(R.multiply, 1 as number, numbers); //=> [1, 1, 2, 6, 24]
4618 * ```
4619 */
4620export function scan<T, TResult>(fn: (acc: TResult, elem: T) => any, acc: TResult, list: readonly T[]): TResult[];
4621export function scan<T, TResult>(fn: (acc: TResult, elem: T) => any, acc: TResult): (list: readonly T[]) => TResult[];
4622export function scan<T, TResult>(fn: (acc: TResult, elem: T) => any): (acc: TResult, list: readonly T[]) => TResult[];
4623
4624/**
4625 * Returns the result of "setting" the portion of the given data structure focused by the given lens
4626 * to the given value.
4627 *
4628 * See also {@link view}, {@link over}, {@link lens}, {@link lensIndex}, {@link lensProp}, {@link lensPath}.
4629 *
4630 * @example
4631 * ```typescript
4632 * const xLens = R.lensProp<'x', number>('x');
4633 *
4634 * const point = {x: 1, y: 2};
4635 * R.set(xLens, 4, point); //=> {x: 4, y: 2}
4636 * R.set(xLens, 8, point); //=> {x: 8, y: 2}
4637 * ```
4638 */
4639export function set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;
4640export function set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
4641export function set<S, A>(lens: Lens<S, A>): (a: A, obj: S) => S;
4642
4643/**
4644 * Returns the elements of the given list or string
4645 * from `fromIndex` (inclusive) to `toIndex` (exclusive).
4646 *
4647 * Dispatches to the `slice` method of the third argument, if present.
4648 *
4649 * @example
4650 * ```typescript
4651 * R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
4652 * R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
4653 * R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
4654 * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
4655 * R.slice(0, 3, 'ramda'); //=> 'ram'
4656 * ```
4657 */
4658export function slice(a: number, b: number, list: string): string;
4659export function slice<T>(a: number, b: number, list: readonly T[]): T[];
4660export function slice(
4661 a: number,
4662 b: number,
4663): {
4664 <T>(list: readonly T[]): T[];
4665 (list: string): string;
4666};
4667export function slice(a: number): {
4668 <T>(b: number, list: readonly T[]): T[];
4669 (b: number, list: string): string;
4670};
4671
4672/**
4673 * Returns a copy of the list, sorted according to the comparator function,
4674 * which should accept two values at a time and return:
4675 * - a negative number if the first value is smaller,
4676 * - a positive number if it's larger, and
4677 * - zero if they are equal.
4678 *
4679 * See also {@link sortBy}, {@link sortWith}, {@link ascend}, {@link descend}.
4680 *
4681 * @example
4682 * ```typescript
4683 * R.sort(R.subtract, [4,2,7,5]); //=> [2, 4, 5, 7]
4684 * ```
4685 */
4686export function sort<T>(fn: (a: T, b: T) => number, list: readonly T[]): T[];
4687export function sort<T>(fn: (a: T, b: T) => number): (list: readonly T[]) => T[];
4688
4689/**
4690 * Sorts the list according to a key generated by the supplied function.
4691 *
4692 * See also {@link sort}, {@link sortWith}, {@link ascend}, {@link descend}.
4693 *
4694 * @example
4695 * ```typescript
4696 * type Person = { name: string; age: number; };
4697 *
4698 * const sortByFirstItem = R.sortBy(R.prop(0));
4699 * const pairs = [[-1, 1], [-2, 2], [-3, 3]];
4700 * sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]]
4701 * const sortByNameCaseInsensitive = R.sortBy<Person>(R.compose(R.toLower, R.prop('name')));
4702 * const alice = {
4703 * name: 'ALICE',
4704 * age: 101
4705 * };
4706 * const bob = {
4707 * name: 'Bob',
4708 * age: -10
4709 * };
4710 * const clara = {
4711 * name: 'clara',
4712 * age: 314.159
4713 * };
4714 * const people = [clara, bob, alice];
4715 * sortByNameCaseInsensitive(people); //=> [alice, bob, clara]
4716 * ```
4717 */
4718export function sortBy<T>(fn: (a: T) => Ord, list: readonly T[]): T[];
4719export function sortBy<T>(fn: (a: T) => Ord): (list: readonly T[]) => T[];
4720export function sortBy(fn: (a: any) => Ord): <T>(list: readonly T[]) => T[];
4721
4722/**
4723 * Sorts a list according to a list of comparators.
4724 *
4725 * See also {@link sort}, {@link sortBy}, {@link ascend}, {@link descend}.
4726 *
4727 * @example
4728 * ```typescript
4729 * type Person = { age: number; name: string; };
4730 *
4731 * const alice = {
4732 * name: 'alice',
4733 * age: 40
4734 * };
4735 * const bob = {
4736 * name: 'bob',
4737 * age: 30
4738 * };
4739 * const clara = {
4740 * name: 'clara',
4741 * age: 40
4742 * };
4743 * const people = [clara, bob, alice];
4744 * const ageNameSort = R.sortWith<Person>([
4745 * R.descend(R.prop('age')),
4746 * R.ascend(R.prop('name'))
4747 * ]);
4748 * ageNameSort(people); //=> [alice, clara, bob]
4749 * ```
4750 */
4751export function sortWith<T>(fns: ReadonlyArray<(a: T, b: T) => number>, list: readonly T[]): T[];
4752export function sortWith<T>(fns: ReadonlyArray<(a: T, b: T) => number>): (list: readonly T[]) => T[];
4753
4754/**
4755 * Splits a string into an array of strings based on the given separator.
4756 *
4757 * See also {@link join}.
4758 *
4759 * @example
4760 * ```typescript
4761 * const pathComponents = R.split('/');
4762 * R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']
4763 *
4764 * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']
4765 * ```
4766 */
4767export function split(sep: string | RegExp): (str: string) => string[];
4768export function split(sep: string | RegExp, str: string): string[];
4769
4770/**
4771 * Splits a given list or string at a given index.
4772 *
4773 * @example
4774 * ```typescript
4775 * R.splitAt(1, [1, 2, 3]); //=> [[1], [2, 3]]
4776 * R.splitAt(5, 'hello world'); //=> ['hello', ' world']
4777 * R.splitAt(-1, 'foobar'); //=> ['fooba', 'r']
4778 * ```
4779 */
4780export function splitAt<T>(index: number, list: readonly T[]): [T[], T[]];
4781export function splitAt(index: number, list: string): [string, string];
4782export function splitAt(index: number): {
4783 <T>(list: readonly T[]): [T[], T[]];
4784 (list: string): [string, string];
4785};
4786
4787/**
4788 * Splits a collection into slices of the specified length.
4789 *
4790 * @example
4791 * ```typescript
4792 * R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]]
4793 * R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz']
4794 * ```
4795 */
4796export function splitEvery<T>(a: number, list: readonly T[]): T[][];
4797export function splitEvery(a: number, list: string): string[];
4798export function splitEvery(a: number): {
4799 (list: string): string[];
4800 <T>(list: readonly T[]): T[][];
4801};
4802
4803/**
4804 * Takes a list and a predicate and returns a pair of lists.
4805 * The first list contains all elements
4806 * before (but not including) the first element for which the predicate returns a truthy value.
4807 * The second list contains the rest of the elements.
4808 * It will be empty if no elements satisfy the predicate.
4809 *
4810 * @example
4811 * ```typescript
4812 * R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]]
4813 * ```
4814 */
4815export function splitWhen<T>(pred: (val: T) => boolean, list: readonly T[]): [T[], T[]];
4816export function splitWhen<T>(pred: (val: T) => boolean): <U extends T>(list: readonly U[]) => [U[], U[]];
4817
4818/**
4819 * Splits an array into slices on every occurrence of a value.
4820 *
4821 * @example
4822 * ```typescript
4823 * R.splitWhenever(R.equals(2), [1, 2, 3, 2, 4, 5, 2, 6, 7]); //=> [[1], [3], [4, 5], [6, 7]]
4824 * ```
4825 */
4826export function splitWhenever<T>(pred: (a: T) => boolean, list: T[]): T[][];
4827export function splitWhenever<T>(pred: (a: T) => boolean): <U extends T>(list: U[]) => U[][];
4828
4829/**
4830 * Checks if a list starts with the provided sublist.
4831 *
4832 * Similarly, checks if a string starts with the provided substring.
4833 *
4834 * See also {@link endsWith}.
4835 *
4836 * @example
4837 * ```typescript
4838 * R.startsWith('a', 'abc') //=> true
4839 * R.startsWith('b', 'abc') //=> false
4840 * R.startsWith(['a'], ['a', 'b', 'c']) //=> true
4841 * R.startsWith(['b'], ['a', 'b', 'c']) //=> false
4842 * ```
4843 */
4844export function startsWith(substr: string, str: string): boolean;
4845export function startsWith(substr: string): (str: string) => boolean;
4846export function startsWith<T>(subList: readonly T[], list: readonly T[]): boolean;
4847export function startsWith<T>(subList: readonly T[]): (list: readonly T[]) => boolean;
4848
4849/**
4850 * Subtracts two numbers. Equivalent to `a - b` but curried.
4851 *
4852 * @example
4853 * ```typescript
4854 * R.subtract(10, 8); //=> 2
4855 *
4856 * const minus5 = R.subtract(R.__, 5);
4857 * minus5(17); //=> 12
4858 *
4859 * const complementaryAngle = R.subtract(90);
4860 * complementaryAngle(30); //=> 60
4861 * complementaryAngle(72); //=> 18
4862 * ```
4863 */
4864export function subtract(__: Placeholder, b: number): (a: number) => number;
4865export function subtract(__: Placeholder): (b: number, a: number) => number;
4866export function subtract(a: number, b: number): number;
4867export function subtract(a: number): (b: number) => number;
4868
4869/**
4870 * Adds together all the elements of a list.
4871 *
4872 * See also {@link reduce}.
4873 *
4874 * @example
4875 * ```typescript
4876 * R.sum([2,4,6,8,100,1]); //=> 121
4877 * ```
4878 */
4879export function sum(list: readonly number[]): number;
4880
4881/**
4882 * Finds the set (i.e. no duplicates) of all elements
4883 * contained in the first or second list, but not both.
4884 *
4885 * See also {@link symmetricDifferenceWith}, {@link difference}, {@link differenceWith}.
4886 *
4887 * @example
4888 * ```typescript
4889 * R.symmetricDifference([1,2,3,4], [7,6,5,4,3]); //=> [1,2,7,6,5]
4890 * R.symmetricDifference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5,1,2]
4891 * ```
4892 */
4893export function symmetricDifference<T>(list1: readonly T[], list2: readonly T[]): T[];
4894export function symmetricDifference<T>(list: readonly T[]): <T>(list: readonly T[]) => T[];
4895
4896/**
4897 * Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both.
4898 * Duplication is determined according to the value returned by applying the supplied predicate to two list elements.
4899 *
4900 * @example
4901 * ```typescript
4902 * const eqA = R.eqBy(R.prop<number>('a'));
4903 * const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}];
4904 * const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}];
4905 * R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
4906 * ```
4907 */
4908export function symmetricDifferenceWith<T>(
4909 pred: (a: T, b: T) => boolean,
4910 list1: readonly T[],
4911 list2: readonly T[],
4912): T[];
4913export function symmetricDifferenceWith<T>(
4914 pred: (a: T, b: T) => boolean,
4915): _.F.Curry<(a: readonly T[], b: readonly T[]) => T[]>;
4916
4917/**
4918 * A function that always returns `true`. Any passed in parameters are ignored.
4919 *
4920 * See also {@link F}.
4921 *
4922 * @example
4923 * ```typescript
4924 * R.T(); //=> true
4925 * ```
4926 */
4927export function T(...args: unknown[]): true;
4928
4929/**
4930 * Returns all but the first element of a list or string.
4931 *
4932 * @example
4933 * ```typescript
4934 * R.tail([1, 2, 3]); //=> [2, 3]
4935 * R.tail([1, 2]); //=> [2]
4936 * R.tail([1]); //=> []
4937 * R.tail([]); //=> []
4938 *
4939 * R.tail('abc'); //=> 'bc'
4940 * R.tail('ab'); //=> 'b'
4941 * R.tail('a'); //=> ''
4942 * R.tail(''); //=> ''
4943 * ```
4944 */
4945export function tail(list: string): string;
4946export function tail<T>(list: readonly T[]): T[];
4947
4948/**
4949 * Returns the first (at most) `n` elements of the given list, string, or transducer/transformer.
4950 *
4951 * Dispatches to the `take` method of the second argument, if present.
4952 *
4953 * See also {@link drop}.
4954 *
4955 * @example
4956 * ```typescript
4957 * R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
4958 * R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
4959 * R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
4960 * R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
4961 * R.take(3, 'ramda'); //=> 'ram'
4962 *
4963 * const personnel = [
4964 * 'Dave Brubeck',
4965 * 'Paul Desmond',
4966 * 'Eugene Wright',
4967 * 'Joe Morello',
4968 * 'Gerry Mulligan',
4969 * 'Bob Bates',
4970 * 'Joe Dodge',
4971 * 'Ron Crotty'
4972 * ];
4973 *
4974 * const takeFive = R.take(5);
4975 * takeFive(personnel);
4976 * //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']
4977 * ```
4978 */
4979export function take<T>(n: number, xs: readonly T[]): T[];
4980export function take(n: number, xs: string): string;
4981export function take(n: number): {
4982 (xs: string): string;
4983 <T>(xs: readonly T[]): T[];
4984};
4985export function take<T>(n: number): (xs: readonly T[]) => T[];
4986
4987/**
4988 * Returns a new list containing the last (at most) `n` elements of the given list.
4989 *
4990 * See also {@link dropLast}.
4991 *
4992 * @example
4993 * ```typescript
4994 * R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz']
4995 * R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
4996 * R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
4997 * R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
4998 * R.takeLast(3, 'ramda'); //=> 'mda'
4999 * ```
5000 */
5001export function takeLast<T>(n: number, xs: readonly T[]): T[];
5002export function takeLast(n: number, xs: string): string;
5003export function takeLast(n: number): {
5004 (xs: string): string;
5005 <T>(xs: readonly T[]): T[];
5006};
5007
5008/**
5009 * Returns a new list containing the last elements of a given list,
5010 * passing each value to the supplied predicate function
5011 * and terminating when the predicate function returns a falsy value.
5012 * Excludes the element that caused the predicate function to fail.
5013 *
5014 * See also {@link dropLastWhile}, {@link addIndex}.
5015 */
5016export function takeLastWhile<T>(pred: (a: T) => boolean, list: readonly T[]): T[];
5017export function takeLastWhile<T>(pred: (a: T) => boolean): <T>(list: readonly T[]) => T[];
5018
5019/**
5020 * Returns a new list containing the first elements of a given list,
5021 * passing each value to the supplied predicate function,
5022 * and terminating when the predicate function returns a falsy value.
5023 *
5024 * Dispatches to the `takeWhile` method of the second argument, if present.
5025 *
5026 * Acts as a transducer if a transformer is given in list position.
5027 *
5028 * See also {@link dropWhile}, {@link addIndex}, {@link transduce}.
5029 */
5030export function takeWhile<T>(fn: (x: T) => boolean, list: readonly T[]): T[];
5031export function takeWhile<T>(fn: (x: T) => boolean): (list: readonly T[]) => T[];
5032
5033/**
5034 * Runs the given function with the supplied object, then returns the object.
5035 * Acts as a transducer if a transformer is given as second parameter.
5036 *
5037 * @example
5038 * ```typescript
5039 * const sayX = <T>(x: T) => console.log('x is ' + x);
5040 * R.tap(sayX, 100); //=> 100
5041 * // logs 'x is 100'
5042 * ```
5043 */
5044export function tap<T, R extends T = T>(fn: (a: T) => asserts a is R, value: T): R;
5045export function tap<T, R extends T = T>(fn: (a: T) => asserts a is R): (value: T) => R;
5046export function tap<T>(fn: (a: T) => void, value: T): T;
5047export function tap<T>(fn: (a: T) => void): (value: T) => T;
5048
5049/**
5050 * Determines whether a given string matches a given regular expression.
5051 *
5052 * See also {@link match}.
5053 *
5054 * @example
5055 * ```typescript
5056 * R.test(/^x/, 'xyz'); //=> true
5057 * R.test(/^y/, 'xyz'); //=> false
5058 * ```
5059 */
5060export function test(regexp: RegExp, str: string): boolean;
5061export function test(regexp: RegExp): (str: string) => boolean;
5062
5063/**
5064 * Creates a thunk out of a function.
5065 * A thunk delays a calculation until its result is needed,
5066 * providing lazy evaluation of arguments.
5067 *
5068 * See also {@link partial}, {@link partialRight}.
5069 *
5070 * @example
5071 * ```typescript
5072 * R.thunkify(R.identity)(42)(); //=> 42
5073 * R.thunkify((a: number, b: number) => a + b)(25, 17)(); //=> 42
5074 * ```
5075 */
5076export function thunkify<F extends AnyFunction>(fn: F): _.F.Curry<(...args: Parameters<F>) => () => ReturnType<F>>;
5077
5078/**
5079 * Calls an input function `n` times,
5080 * returning an array containing the results of those function calls.
5081 *
5082 * `fn` is passed one argument:
5083 * The current value of `n`,
5084 * which begins at `0` and is gradually incremented to `n - 1`.
5085 *
5086 * See also {@link repeat}.
5087 *
5088 * @example
5089 * ```typescript
5090 * R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]
5091 * ```
5092 */
5093export function times<T>(fn: (i: number) => T, n: number): T[];
5094export function times<T>(fn: (i: number) => T): (n: number) => T[];
5095
5096/**
5097 * The lower case version of a string.
5098 *
5099 * See also {@link toUpper}.
5100 *
5101 * @example
5102 * ```typescript
5103 * R.toLower('XYZ'); //=> 'xyz'
5104 * ```
5105 */
5106export function toLower<S extends string>(str: S): Lowercase<S>;
5107export function toLower(str: string): string;
5108
5109/**
5110 * Converts an object into an array of key, value arrays.
5111 * Only the object's own properties are used.
5112 * Note that the order of the output array is not guaranteed to be consistent
5113 * across different JS platforms.
5114 *
5115 * See also {@link toPairsIn}, {@link fromPairs}, {@link keys}, {@link values}.
5116 */
5117export function toPairs<O extends object, K extends Extract<keyof O, string | number>>(
5118 obj: O,
5119): Array<{ [key in K]: [`${key}`, O[key]] }[K]>;
5120export function toPairs<S>(obj: Record<string | number, S>): Array<[string, S]>;
5121
5122/**
5123 * Converts an object into an array of key, value arrays.
5124 * The object's own properties and prototype properties are used.
5125 * Note that the order of the output array is not guaranteed to be consistent
5126 * across different JS platforms.
5127 *
5128 * See also {@link toPairs}.=
5129 *
5130 * @example
5131 * ```typescript
5132 * class F {
5133 * x: string;
5134 * y = 'Y';
5135 *
5136 * constructor() {
5137 * this.x = 'X';
5138 * }
5139 * }
5140 *
5141 * const f = new F();
5142 * R.toPairsIn(f); //=> [['x','X'], ['y','Y']]
5143 * ```
5144 */
5145export function toPairsIn<O extends object, K extends Extract<keyof O, string | number>>(
5146 obj: O,
5147): Array<{ [key in K]: [`${key}`, O[key]] }[K]>;
5148export function toPairsIn<S>(obj: Record<string | number, S>): Array<[string, S]>;
5149
5150/**
5151 * Returns the string representation of the given value.
5152 * `eval`'ing the output should result in a value equivalent to the input value.
5153 * Many of the built-in `toString` methods do not satisfy this requirement.
5154 *
5155 * If the given value is an `Object` with a toString method other than `Object.prototype.toString`,
5156 * that method is invoked with no arguments to produce the return value.
5157 * This means user-defined constructor functions can provide a suitable `toString` method.
5158 *
5159 * @example
5160 * ```typescript
5161 * class Point {
5162 * constructor(public x: number, public y: number) {}
5163 *
5164 * toString() {
5165 * return 'new Point(' + this.x + ', ' + this.y + ')';
5166 * }
5167 * }
5168 *
5169 * R.toString(new Point(1, 2)); //=> 'new Point(1, 2)'
5170 * R.toString(42); //=> '42'
5171 * R.toString('abc'); //=> '"abc"'
5172 * R.toString([1, 2, 3]); //=> '[1, 2, 3]'
5173 * R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}'
5174 * R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")'
5175 * ```
5176 */
5177export function toString(val: unknown): string;
5178
5179/**
5180 * The upper case version of a string.
5181 *
5182 * See also {@link toLower}.
5183 *
5184 * @example
5185 * ```typescript
5186 * R.toUpper('abc'); //=> 'ABC'
5187 * ```
5188 */
5189export function toUpper<S extends string>(str: S): Uppercase<S>;
5190export function toUpper(str: string): string;
5191
5192/**
5193 * Initializes a transducer using supplied iterator function.
5194 * Returns a single item by iterating through the list,
5195 * successively calling the transformed iterator function
5196 * and passing it an accumulator value and the current value from the array,
5197 * and then passing the result to the next call.
5198 *
5199 * The iterator function receives two values: `(acc, value)`.
5200 * It will be wrapped as a transformer to initialize the transducer.
5201 * A transformer can be passed directly in place of an iterator function.
5202 * In both cases, iteration may be stopped early with the `R.reduced` function.
5203 *
5204 * A transducer is a function that accepts a transformer and returns a transformer and can be composed directly.
5205 *
5206 * The accumulator can also be a transformer object that provides:
5207 * - A 2-arity iterator function, which is passed directly to reduce.
5208 * - A 0-arity initial value function, which is used to provide the initial accumulator.
5209 * This is ignored by `R.transduce`.
5210 * - A 1-arity result extraction function, which is used to convert the final accumulator into the return type.
5211 *
5212 * The iteration is performed with `R.reduce` after initializing the transducer.
5213 *
5214 * See also {@link reduce}, {@link reduced}, {@link into}.
5215 *
5216 * @example
5217 * ```typescript
5218 * const numbers = [1, 2, 3, 4];
5219 * const transducer = R.compose(R.map(R.add(1)), R.take<number>(2));
5220 * R.transduce(transducer, R.flip<number, number[], number[]>(R.append), [], numbers); //=> [2, 3]
5221 *
5222 * const isOdd = (x: number) => x % 2 !== 0;
5223 * const firstOddTransducer = R.compose(R.filter(isOdd), R.take(1));
5224 * R.transduce(firstOddTransducer, R.flip<number, number[], number[]>(R.append), [], R.range(0, 100)); //=> [1]
5225 * ```
5226 */
5227export function transduce<T, U, V>(
5228 xf: (arg: readonly T[]) => U[],
5229 fn: (acc: V, val: U) => V,
5230 acc: V,
5231 list: readonly T[],
5232): V;
5233export function transduce<T, U, V>(
5234 xf: (arg: readonly T[]) => U[],
5235): (fn: (acc: V, val: U) => V, acc: V, list: readonly T[]) => V;
5236export function transduce<T, U, V>(
5237 xf: (arg: readonly T[]) => U[],
5238 fn: (acc: V, val: U) => V,
5239): (acc: readonly T[], list: readonly T[]) => V;
5240export function transduce<T, U, V>(
5241 xf: (arg: readonly T[]) => U[],
5242 fn: (acc: V, val: U) => V,
5243 acc: readonly T[],
5244): (list: readonly T[]) => V;
5245
5246/**
5247 * Transposes the rows and columns of a 2D list.
5248 * When passed a list of `n` lists of length `x`,
5249 * returns a list of `x` lists of length `n`.
5250 *
5251 * @example
5252 * ```typescript
5253 * R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]) //=> [[1, 2, 3], ['a', 'b', 'c']]
5254 * R.transpose<string | number>([[1, 2, 3], ['a', 'b', 'c']]) //=> [[1, 'a'], [2, 'b'], [3, 'c']]
5255 *
5256 * // If some of the rows are shorter than the following rows, their elements are skipped:
5257 * R.transpose([[10, 11], [20], [], [30, 31, 32]]) //=> [[10, 20, 30], [11, 31], [32]]
5258 * ```
5259 */
5260export function transpose<T>(list: readonly T[][]): T[][];
5261
5262/**
5263 * Maps an `Applicative`-returning function over a `Traversable`,
5264 * then uses `R.sequence` to transform the resulting `Traversable` of `Applicative`
5265 * into an `Applicative` of `Traversable`.
5266 *
5267 * Dispatches to the `traverse` method of the third argument, if present.
5268 *
5269 * See also {@link sequence}.
5270 *
5271 * @example
5272 * ```typescript
5273 * // Returns `[]` if the given divisor is `0`
5274 * const safeDiv = (n: number) => (d: number) => d === 0 ? [] : Array.of(n / d)
5275 *
5276 * R.traverse(Array.of, safeDiv(10), [2, 4, 5]); //=> [[5, 2.5, 2]]
5277 * R.traverse(Array.of, safeDiv(10), [2, 0, 5]); //=> []
5278 * ```
5279 */
5280export function traverse<A, B>(of: (a: B) => B[], fn: (t: A) => B[], list: readonly A[]): B[][];
5281export function traverse<A, B>(of: (a: B) => B[], fn: (t: A) => B[]): (list: readonly A[]) => B[][];
5282export function traverse<A, B>(of: (a: B) => B[]): (fn: (t: A) => B[], list: readonly A[]) => B[][];
5283
5284/**
5285 * Removes (strips) whitespace from both ends of the string.
5286 *
5287 * @example
5288 * ```typescript
5289 * R.trim(' xyz '); //=> 'xyz'
5290 * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']
5291 * ```
5292 */
5293export function trim(str: string): string;
5294
5295/**
5296 * `R.tryCatch` takes two functions, a `tryer` and a `catcher`.
5297 * The returned function evaluates the `tryer`;
5298 * if it does not throw, it simply returns the result.
5299 * If the `tryer` does throw,
5300 * the returned function evaluates the `catcher` function and returns its result.
5301 *
5302 * @note For effective composition with this function,
5303 * both the `tryer` and `catcher` functions must return the same type of results.
5304 *
5305 * @example
5306 * ```typescript
5307 * R.tryCatch(R.prop('x'), R.F)({ x: true }); //=> true
5308 * R.tryCatch((_s: string) => { throw 'foo' }, R.always('caught'))('bar') //=> 'caught'
5309 * // Don't do this, it's just an example
5310 * R.tryCatch(R.times(R.identity), R.always([]))('s' as never) //=> []
5311 * R.tryCatch((_s: string) => { throw 'this is not a valid value' }, (err, value)=>({ error: err, value }))('bar')
5312 * //=> {'error': 'this is not a valid value', 'value': 'bar'}
5313 * ```
5314 */
5315export function tryCatch<F extends AnyFunction, RE = ReturnType<F>, E = unknown>(
5316 tryer: F,
5317 catcher: (error: E, ...args: _.F.Parameters<F>) => RE,
5318): F | (() => RE);
5319export function tryCatch<F extends AnyFunction>(
5320 tryer: F,
5321): <RE = ReturnType<F>, E = unknown>(catcher: (error: E, ...args: _.F.Parameters<F>) => RE) => F | (() => RE);
5322
5323/**
5324 * Gives a single-word string description of the (native) type of a value,
5325 * returning such answers as `'Object'`, `'Number'`, `'Array'`, or `'Null'`.
5326 * Does not attempt to distinguish user `Object` types any further,
5327 * reporting them all as `'Object'`.
5328 *
5329 * Uses `Object.prototype.toString` internally for values other than `null` and `undefined`.
5330 *
5331 * @example
5332 * ```typescript
5333 * R.type({}); //=> "Object"
5334 * R.type(1); //=> "Number"
5335 * R.type(false); //=> "Boolean"
5336 * R.type('s'); //=> "String"
5337 * R.type(null); //=> "Null"
5338 * R.type([]); //=> "Array"
5339 * R.type(/[A-z]/); //=> "RegExp"
5340 * R.type(() => {}); //=> "Function"
5341 * R.type(undefined); //=> "Undefined"
5342 * ```
5343 */
5344export function type(
5345 val: any,
5346):
5347 | 'Object'
5348 | 'Number'
5349 | 'Boolean'
5350 | 'String'
5351 | 'Null'
5352 | 'Array'
5353 | 'RegExp'
5354 | 'Function'
5355 | 'Undefined'
5356 | 'Symbol'
5357 | 'Error';
5358
5359/**
5360 * Takes a function `fn`, which takes a single array argument, and returns a function which:
5361 * - takes any number of positional arguments;
5362 * - passes these arguments to fn as an array; and
5363 * - returns the result.
5364 *
5365 * In other words, `R.unapply` derives a variadic function from a function which takes an array.
5366 * `R.unapply` is the inverse of `R.apply`.
5367 *
5368 * See also {@link apply}.
5369 *
5370 * @example
5371 * ```typescript
5372 * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]'
5373 * ```
5374 */
5375export function unapply<T>(fn: (args: any[]) => T): (...args: unknown[]) => T;
5376
5377/**
5378 * Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter.
5379 * Any extraneous parameters will not be passed to the supplied function.
5380 *
5381 * See also {@link binary}, {@link nAry}.
5382 *
5383 * @example
5384 * ```typescript
5385 * const takesTwoArgs = <T, U>(a: T, b: U) => [a, b];
5386 * takesTwoArgs.length; //=> 2
5387 * takesTwoArgs(1, 2); //=> [1, 2]
5388 *
5389 * const takesOneArg = R.unary(takesTwoArgs);
5390 * takesOneArg.length; //=> 1
5391 * // Only 1 argument is passed to the wrapped function
5392 * takesOneArg(1); //=> [1, undefined]
5393 * ```
5394 */
5395export function unary<T, R>(fn: (a: T, ...args: any[]) => R): (a: T) => R;
5396
5397/**
5398 * Returns a function of arity n from a (manually) curried function.
5399 *
5400 * @note The returned function is actually a ramda style curryied function,
5401 * which can accept one or more arguments in each function calling.
5402 *
5403 * @example
5404 * ```typescript
5405 * const addFour = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d;
5406 *
5407 * const uncurriedAddFour = R.uncurryN<number>(4, addFour);
5408 * uncurriedAddFour(1, 2, 3, 4); //=> 10
5409 * ```
5410 */
5411export function uncurryN<T>(len: number, fn: (a: any) => any): (...args: unknown[]) => T;
5412export function uncurryN<T>(len: number): (fn: (a: any) => any) => (...args: unknown[]) => T;
5413
5414/**
5415 * Builds a list from a seed value.
5416 * Accepts an iterator function, which returns either a falsy value to stop iteration
5417 * or an array of length 2 containing the value to add to the resulting list
5418 * and the seed to be used in the next call to the iterator function.
5419 *
5420 * @example
5421 * ```typescript
5422 * const f = (n: number) => n > 50 ? false : [-n, n + 10] as const;
5423 * R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]
5424 * ```
5425 */
5426export function unfold<T, TResult>(fn: (seed: T) => [TResult, T] | false, seed: T): TResult[];
5427export function unfold<T, TResult>(fn: (seed: T) => [TResult, T] | false): (seed: T) => TResult[];
5428
5429/**
5430 * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list.
5431 *
5432 * @example
5433 * ```typescript
5434 * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4]
5435 * ```
5436 */
5437export function union<T>(as: readonly T[], bs: readonly T[]): T[];
5438export function union<T>(as: readonly T[]): (bs: readonly T[]) => T[];
5439
5440/**
5441 * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list.
5442 * Duplication is determined according to the value returned
5443 * by applying the supplied predicate to two list elements.
5444 * If an element exists in both lists,
5445 * the first element from the first list will be used.
5446 *
5447 * @example
5448 * ```typescript
5449 * const l1 = [{a: 1}, {a: 2}];
5450 * const l2 = [{a: 1}, {a: 4}];
5451 * R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}]
5452 * ```
5453 */
5454export function unionWith<T>(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[];
5455export function unionWith<T>(pred: (a: T, b: T) => boolean): _.F.Curry<(a: readonly T[], b: readonly T[]) => T[]>;
5456
5457/**
5458 * Returns a new list containing only one copy of each element in the original list.
5459 *
5460 * @example
5461 * ```typescript
5462 * R.uniq([1, 1, 2, 1]); //=> [1, 2]
5463 * R.uniq([1, '1']); //=> [1, '1']
5464 * R.uniq([[42], [42]]); //=> [[42]]
5465 * ```
5466 */
5467export function uniq<T>(list: readonly T[]): T[];
5468
5469/**
5470 * Returns a new list containing only one copy of each element in the original list,
5471 * based upon the value returned by applying the supplied function to each list element.
5472 * Prefers the first item if the supplied function produces the same value on two items.
5473 * `R.equals` is used for comparison.
5474 *
5475 * @example
5476 * ```typescript
5477 * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10]
5478 * ```
5479 */
5480export function uniqBy<T, U>(fn: (a: T) => U, list: readonly T[]): T[];
5481export function uniqBy<T, U>(fn: (a: T) => U): (list: readonly T[]) => T[];
5482
5483/**
5484 * Returns a new list containing only one copy of each element in the original list,
5485 * based upon the value returned by applying the supplied predicate to two list elements.
5486 * Prefers the first item if two items compare equal based on the predicate.
5487 *
5488 * Acts as a transducer if a transformer is given in list position.
5489 *
5490 * See also {@link transduce}.
5491 *
5492 * @example
5493 * ```typescript
5494 * const strEq = R.eqBy(String);
5495 * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
5496 * R.uniqWith(strEq)([{}, {}]); //=> [{}]
5497 * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
5498 * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
5499 * ```
5500 */
5501export function uniqWith<T, U>(pred: (x: T, y: T) => boolean, list: readonly T[]): T[];
5502export function uniqWith<T, U>(pred: (x: T, y: T) => boolean): (list: readonly T[]) => T[];
5503
5504/**
5505 * Tests the final argument by passing it to the given predicate function.
5506 * If the predicate is not satisfied,
5507 * the function will return the result of calling the `whenFalseFn` function with the same argument.
5508 * If the predicate is satisfied, the argument is returned as is.
5509 *
5510 * See also {@link ifElse}, {@link when}, {@link cond}.
5511 *
5512 * @example
5513 * ```typescript
5514 * let safeInc = R.unless<number | null | undefined, null | undefined>(R.isNil, R.inc);
5515 * safeInc(null); //=> null
5516 * safeInc(1); //=> 2
5517 * ```
5518 */
5519export function unless<T, U>(pred: (a: T) => boolean, whenFalseFn: (a: T) => U, a: T): T | U;
5520export function unless<T, U>(pred: (a: T) => boolean, whenFalseFn: (a: T) => U): (a: T) => T | U;
5521
5522/**
5523 * Shorthand for `R.chain(R.identity)`,
5524 * which removes one level of nesting from any `Chain`.
5525 *
5526 * See also {@link flatten}, {@link chain}.
5527 *
5528 * @example
5529 * ```typescript
5530 * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]]
5531 * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6]
5532 * ```
5533 */
5534export function unnest<T extends readonly any[]>(list: T): _.T.UnNest<T>;
5535
5536/**
5537 * Takes a predicate, a transformation function, and an initial value,
5538 * and returns a value of the same type as the initial value.
5539 * It does so by applying the transformation until the predicate is satisfied,
5540 * at which point it returns the satisfactory value.
5541 *
5542 * @example
5543 * ```typescript
5544 * R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128
5545 * ```
5546 */
5547export function until<T, U>(pred: (val: T) => boolean, fn: (val: T) => U, init: U): U;
5548export function until<T, U>(pred: (val: T) => boolean, fn: (val: T) => U): (init: U) => U;
5549
5550/**
5551 * Returns a new copy of the array with the element at the provided index replaced with the given value.
5552 *
5553 * See also {@link adjust}.
5554 *
5555 * @example
5556 * ```typescript
5557 * R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c']
5558 * R.update(-1, '_', ['a', 'b', 'c']); //=> ['a', 'b', '_']
5559 * ```
5560 */
5561export function update<T>(index: number, value: T, list: readonly T[]): T[];
5562export function update<T>(index: number, value: T): (list: readonly T[]) => T[];
5563
5564/**
5565 * Accepts a function fn and a list of transformer functions and returns a new curried function.
5566 * When the new function is invoked,
5567 * it calls the function fn with parameters
5568 * consisting of the result of calling each supplied handler on successive arguments to the new function.
5569 *
5570 * If more arguments are passed to the returned function than transformer functions,
5571 * those arguments are passed directly to fn as additional parameters.
5572 * If you expect additional arguments that don't need to be transformed,
5573 * although you can ignore them,
5574 * it's best to pass an identity function
5575 * so that the new function reports the correct arity.
5576 *
5577 * See also {@link converge}.
5578 *
5579 * @example
5580 * ```typescript
5581 * R.useWith(Math.pow, [(n: number) => n, (n: number) => n])(3, 4); //=> 81
5582 * R.useWith(Math.pow, [(n: number) => n, (n: number) => n])(3)(4); //=> 81
5583 * R.useWith(Math.pow, [R.dec, R.inc])(3, 4); //=> 32
5584 * R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32
5585 * ```
5586 */
5587export function useWith<
5588 TArg1,
5589 TR1,
5590 TArg2,
5591 TR2,
5592 TArg3,
5593 TR3,
5594 TArg4,
5595 TR4,
5596 TArg5,
5597 TR5,
5598 TArg6,
5599 TR6,
5600 TArg7,
5601 TR7,
5602 TResult,
5603 RestFunctions extends AnyFunction[],
5604 TArgs extends [TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, ...InputTypesOfFns<RestFunctions>],
5605>(
5606 fn: (...args: [TR1, TR2, TR3, TR4, TR5, TR6, TR7, ...ReturnTypesOfFns<RestFunctions>]) => TResult,
5607 transformers: [
5608 (arg: TArg1) => TR1,
5609 (arg: TArg2) => TR2,
5610 (arg: TArg3) => TR3,
5611 (arg: TArg4) => TR4,
5612 (arg: TArg5) => TR5,
5613 (arg: TArg6) => TR6,
5614 (arg: TArg7) => TR7,
5615 ...RestFunctions,
5616 ],
5617): (...args: TArgs) => TResult;
5618export function useWith<TArg1, TR1, TArg2, TR2, TArg3, TR3, TArg4, TR4, TArg5, TR5, TArg6, TR6, TArg7, TR7, TResult>(
5619 fn: (...args: [TR1, TR2, TR3, TR4, TR5, TR6, TR7] & { length: 7 }) => TResult,
5620 transformers: [
5621 (arg: TArg1) => TR1,
5622 (arg: TArg2) => TR2,
5623 (arg: TArg3) => TR3,
5624 (arg: TArg4) => TR4,
5625 (arg: TArg5) => TR5,
5626 (arg: TArg6) => TR6,
5627 (arg: TArg7) => TR7,
5628 ],
5629): (...args: [TArg1, TArg2, TArg3, TArg4, TArg5, TArg7]) => TResult;
5630export function useWith<TArg1, TR1, TArg2, TR2, TArg3, TR3, TArg4, TR4, TArg5, TR5, TArg6, TR6, TResult>(
5631 fn: (...args: [TR1, TR2, TR3, TR4, TR5, TR6] & { length: 6 }) => TResult,
5632 transformers: [
5633 (arg: TArg1) => TR1,
5634 (arg: TArg2) => TR2,
5635 (arg: TArg3) => TR3,
5636 (arg: TArg4) => TR4,
5637 (arg: TArg5) => TR5,
5638 (arg: TArg6) => TR6,
5639 ],
5640): (...args: [TArg1, TArg2, TArg3, TArg4, TArg5, TArg6]) => TResult;
5641export function useWith<TArg1, TR1, TArg2, TR2, TArg3, TR3, TArg4, TR4, TArg5, TR5, TResult>(
5642 fn: (...args: [TR1, TR2, TR3, TR4, TR5] & { length: 5 }) => TResult,
5643 transformers: [
5644 (arg: TArg1) => TR1,
5645 (arg: TArg2) => TR2,
5646 (arg: TArg3) => TR3,
5647 (arg: TArg4) => TR4,
5648 (arg: TArg5) => TR5,
5649 ],
5650): (...args: [TArg1, TArg2, TArg3, TArg4, TArg5]) => TResult;
5651export function useWith<TArg1, TR1, TArg2, TR2, TArg3, TR3, TArg4, TR4, TResult>(
5652 fn: (...args: [TR1, TR2, TR3, TR4] & { length: 4 }) => TResult,
5653 transformers: [(arg: TArg1) => TR1, (arg: TArg2) => TR2, (arg: TArg3) => TR3, (arg: TArg4) => TR4],
5654): (...args: [TArg1, TArg2, TArg3, TArg4]) => TResult;
5655export function useWith<TArg1, TR1, TArg2, TR2, TArg3, TR3, TResult>(
5656 fn: (...args: [TR1, TR2, TR3] & { length: 3 }) => TResult,
5657 transformers: [(arg: TArg1) => TR1, (arg: TArg2) => TR2, (arg: TArg3) => TR3],
5658): (...args: [TArg1, TArg2, TArg3]) => TResult;
5659export function useWith<TArg1, TR1, TArg2, TR2, TResult>(
5660 fn: (...args: [TR1, TR2] & { length: 2 }) => TResult,
5661 transformers: [(arg: TArg1) => TR1, (arg: TArg2) => TR2],
5662): (...args: [TArg1, TArg2]) => TResult;
5663export function useWith<TArg1, TR1, TResult>(
5664 fn: (...args: [TR1]) => TResult,
5665 transformers: [(arg: TArg1) => TR1],
5666): (...args: [TArg1]) => TResult;
5667
5668/**
5669 * Returns a list of all the enumerable own properties of the supplied object.
5670 *
5671 * @note The order of the output array is not guaranteed across different JS platforms.
5672 *
5673 * See also {@link valuesIn}, {@link keys}, {@link toPairs}.
5674 *
5675 * @example
5676 * ```typescript
5677 * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]
5678 * ```
5679 */
5680export function values<T extends object, K extends keyof T>(obj: T): Array<T[K] | ValueOfUnion<T>>;
5681
5682/**
5683 * Returns a list of all the properties, including prototype properties, of the supplied
5684 * object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.
5685 *
5686 * See also {@link values}, {@link keysIn}.
5687 *
5688 * @example
5689 * ```typescript
5690 * lass F {
5691 * x: string;
5692 * y = 'Y';
5693 *
5694 * constructor() {
5695 * this.x = 'X';
5696 * }
5697 * }
5698 *
5699 * const f = new F();
5700 * R.valuesIn(f); //=> ['X', 'Y']
5701 * ```
5702 */
5703export function valuesIn<T>(obj: any): T[];
5704
5705/**
5706 * Returns a "view" of the given data structure, determined by the given lens.
5707 * The lens's focus determines which portion of the data structure is visible.
5708 *
5709 * See also {@link set}, {@link over}, {@link lens}, {@link lensIndex}, {@link lensProp}, {@link lensPath}.
5710 *
5711 * @example
5712 * ```typescript
5713 * const xLens = R.lensProp('x');
5714 *
5715 * const a = {x: 1, y: 2};
5716 * R.view(xLens, a); //=> 1
5717 * const b = {x: 4, y: 2};
5718 * R.view(xLens, b); //=> 4
5719 * ```
5720 */
5721export function view<S, A>(lens: Lens<S, A>): (obj: S) => A;
5722export function view<S, A>(lens: Lens<S, A>, obj: S): A;
5723
5724/**
5725 * Tests the final argument by passing it to the given predicate function.
5726 * If the predicate is satisfied,
5727 * the function will return the result of calling the `whenTrueFn` function with the same argument.
5728 * If the predicate is not satisfied, the argument is returned as is.
5729 *
5730 * See also {@link ifElse}, {@link unless}, {@link cond}.
5731 *
5732 * @example
5733 * ```typescript
5734 * // truncate :: String -> String
5735 * const truncate = R.when(
5736 * R.propSatisfies(R.gt(R.__, 10), 'length'),
5737 * R.pipe(R.take(10), R.append('…'), R.join(''))
5738 * );
5739 * truncate('12345'.split('')); //=> '12345'
5740 * truncate('0123456789ABC'.split('')); //=> '0123456789…'
5741 * ```
5742 */
5743export function when<T, U extends T, V>(pred: (a: T) => a is U, whenTrueFn: (a: U) => V, a: T): T | V;
5744export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, a: T): T | U;
5745export function when<T, U extends T, V>(pred: (a: T) => a is U, whenTrueFn: (a: U) => V): (a: T) => T | V;
5746export function when<T, U>(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (a: T) => T | U;
5747
5748/**
5749 * Takes a spec object and a test object and returns true if the test satisfies the spec.
5750 * Any property on the spec that is not a function
5751 * is interpreted as an equality relation.
5752 *
5753 * If the spec has a property mapped to a function,
5754 * then `where` evaluates the function,
5755 * passing in the test object's value for the property in question,
5756 * as well as the whole test object.
5757 *
5758 * `R.where` is well suited to declaratively expressing constraints for other functions,
5759 * e.g., `R.filter`, `R.find`, `R.pickWith`, etc.
5760 *
5761 * Seee also {@link propSatisfies}, {@link whereEq}.
5762 *
5763 * @example
5764 * ```typescript
5765 * // pred :: Object -> Boolean
5766 * const pred = R.where({
5767 * a: R.equals('foo'),
5768 * b: R.complement(R.equals('bar')),
5769 * x: R.gt(R.__, 10),
5770 * y: R.lt(R.__, 20)
5771 * });
5772 *
5773 * pred({a: 'foo', b: 'xxx', x: 11, y: 19}); //=> true
5774 * pred({a: 'xxx', b: 'xxx', x: 11, y: 19}); //=> false
5775 * pred({a: 'foo', b: 'bar', x: 11, y: 19}); //=> false
5776 * pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false
5777 * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false
5778 * ```
5779 */
5780export function where<T, U>(spec: T, testObj: U): boolean;
5781export function where<T>(spec: T): <U>(testObj: U) => boolean;
5782export function where<ObjFunc2, U>(spec: ObjFunc2, testObj: U): boolean;
5783export function where<ObjFunc2>(spec: ObjFunc2): <U>(testObj: U) => boolean;
5784
5785/**
5786 * Takes a spec object and a test object; returns `true` if the test satisfies the spec, `false` otherwise.
5787 * An object satisfies the spec if, for each of the spec's own properties,
5788 * accessing that property of the object gives the same value (in `R.eq` terms)
5789 * as accessing that property of the spec.
5790 *
5791 * `R.whereEq` is a specialization of `R.where`.
5792 *
5793 * See also {@link propEq}, {@link where}.
5794 *
5795 * @example
5796 * ```typescript
5797 * // pred :: Object -> Boolean
5798 * const pred = R.whereEq({a: 1, b: 2});
5799 *
5800 * pred({a: 1}); //=> false
5801 * pred({a: 1, b: 2}); //=> true
5802 * pred({a: 1, b: 2, c: 3}); //=> true
5803 * pred({a: 1, b: 1}); //=> false
5804 * ```
5805 */
5806export function whereEq<T, U>(spec: T, obj: U): boolean;
5807export function whereEq<T>(spec: T): <U>(obj: U) => boolean;
5808
5809/**
5810 * Returns a new list without values in the first argument.
5811 * `R.equals` is used to determine equality.
5812 * Acts as a transducer if a transformer is given in list position.
5813 *
5814 * See also {@link transduce}, {@link difference}, {@link remove}.
5815 *
5816 * @example
5817 * ```typescript
5818 * R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4]
5819 * ```
5820 */
5821export function without<T>(list1: readonly unknown[], list2: readonly T[]): T[];
5822export function without<T>(list1: readonly T[] | readonly unknown[]): (list2: readonly T[]) => T[];
5823
5824/**
5825 * Exclusive disjunction logical operation.
5826 * Returns `true` if one of the arguments is truthy and the other is falsy.
5827 * Otherwise, it returns `false`.
5828 *
5829 * See also {@link or}, {@link and}.
5830 *
5831 * @example
5832 * ```typescript
5833 * R.xor(true, true); //=> false
5834 * R.xor(true, false); //=> true
5835 * R.xor(false, true); //=> true
5836 * R.xor(false, false); //=> false
5837 * ```
5838 */
5839export function xor(a: any, b: any): boolean;
5840export function xor(a: any): (b: any) => boolean;
5841
5842/**
5843 * Creates a new list out of the two supplied by creating each possible pair from the lists
5844 *
5845 * Short for cross product.
5846 *
5847 * @example
5848 * ```typescript
5849 * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
5850 * ```
5851 */
5852export function xprod<K, V>(as: readonly K[], bs: readonly V[]): Array<KeyValuePair<K, V>>;
5853export function xprod<K>(as: readonly K[]): <V>(bs: readonly V[]) => Array<KeyValuePair<K, V>>;
5854
5855/**
5856 * Creates a new list out of the two supplied
5857 * by pairing up equally-positioned items from both lists.
5858 * The returned list is truncated
5859 * to the length of the shorter of the two input lists.
5860 *
5861 * @note `R.zip` is equivalent to `R.zipWith((a, b) => [a, b] as const)`.
5862 *
5863 * @example
5864 * ```typescript
5865 * R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
5866 * ```
5867 */
5868export function zip<K, V>(list1: readonly K[], list2: readonly V[]): Array<KeyValuePair<K, V>>;
5869export function zip<K>(list1: readonly K[]): <V>(list2: readonly V[]) => Array<KeyValuePair<K, V>>;
5870
5871/**
5872 * Creates a new object out of a list of keys and a list of values.
5873 * Key/value pairing is truncated to the length of the shorter of the two lists.
5874 *
5875 * @note `R.zipObj` is equivalent to `R.pipe(R.zip, R.fromPairs)`.
5876 *
5877 * @example
5878 * ```typescript
5879 * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
5880 * ```
5881 */
5882// TODO: Dictionary<T> as a return value is to specific, any seems to loose
5883export function zipObj<T, K extends string>(keys: readonly K[], values: readonly T[]): { [P in K]: T };
5884export function zipObj<K extends string>(keys: readonly K[]): <T>(values: readonly T[]) => { [P in K]: T };
5885export function zipObj<T, K extends number>(keys: readonly K[], values: readonly T[]): { [P in K]: T };
5886export function zipObj<K extends number>(keys: readonly K[]): <T>(values: readonly T[]) => { [P in K]: T };
5887
5888/**
5889 * Creates a new list out of the two supplied
5890 * by applying the function to each equally-positioned pair in the lists.
5891 *
5892 * @example
5893 * ```typescript
5894 * const f = (x: number, y: string) => [x, y] as const;
5895 * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
5896 * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]
5897 * ```
5898 */
5899export function zipWith<T, U, TResult>(
5900 fn: (x: T, y: U) => TResult,
5901 list1: readonly T[],
5902 list2: readonly U[],
5903): TResult[];
5904export function zipWith<T, U, TResult>(
5905 fn: (x: T, y: U) => TResult,
5906 list1: readonly T[],
5907): (list2: readonly U[]) => TResult[];
5908export function zipWith<T, U, TResult>(
5909 fn: (x: T, y: U) => TResult,
5910): (list1: readonly T[], list2: readonly U[]) => TResult[];
5911
5912/**
5913 * Creates a copy of the passed object by applying an fn function to the given prop property.
5914 * The function will not be invoked, and the object will not change if its corresponding property does not exist in the object.
5915 * All non-primitive properties are copied to the new object by reference.
5916 *
5917 * @example
5918 * ```typescript
5919 * const person = {name: 'James', age: 20, pets: ['dog', 'cat']};
5920 * R.modify('age', R.add(1), person); //=> {name: 'James', age: 21, pets: ['dog', 'cat']}
5921 * R.modify('pets', R.append('turtle'), person); //=> {name: 'James', age: 20, pets: ['dog', 'cat', 'turtle']}
5922 * ```
5923 */
5924export function modify<T extends object, K extends keyof T, P>(
5925 prop: K,
5926 fn: (a: T[K]) => P,
5927 obj: T,
5928): Omit<T, K> & Record<K, P>;
5929export function modify<K extends string, A, P>(
5930 prop: K,
5931 fn: (a: A) => P,
5932): <T extends Record<K, A>>(target: T) => Omit<T, K> & Record<K, P>;
5933
5934export as namespace R;