UNPKG

57.9 kBTypeScriptView Raw
1export type RambdaTypes = "Object" | "Number" | "Boolean" | "String" | "Null" | "Array" | "RegExp" | "NaN" | "Function" | "Undefined" | "Async" | "Promise" | "Symbol" | "Set" | "Error";
2
3export type IndexedIterator<T, U> = (x: T, i: number) => U;
4export type Iterator<T, U> = (x: T) => U;
5export type ObjectIterator<T, U> = (x: T, prop: string, inputObj: Dictionary<T>) => U;
6type Ord = number | string | boolean | Date;
7type Path = string | (number | string)[];
8type Predicate<T> = (x: T) => boolean;
9export type IndexedPredicate<T> = (x: T, i: number) => boolean;
10export type ObjectPredicate<T> = (x: T, prop: string, inputObj: Dictionary<T>) => boolean;
11export type RamdaPath = (number | string)[];
12type CondPair<T extends any[], R> = [(...val: T) => boolean, (...val: T) => R]
13
14type ValueOfRecord<R> =
15 R extends Record<any, infer T>
16 ? T
17 : never;
18
19interface KeyValuePair<K, V> extends Array<K | V> {
20 0: K;
21 1: V;
22}
23
24export interface Lens {
25 <T, U>(obj: T): U;
26 set<T, U>(str: string, obj: T): U;
27}
28
29type Arity1Fn = (x: any) => any;
30type Arity2Fn = (x: any, y: any) => any;
31
32type Pred = (...x: any[]) => boolean;
33type SafePred<T> = (...x: T[]) => boolean;
34
35export interface Dictionary<T> {[index: string]: T}
36type Partial<T> = { [P in keyof T]?: T[P]};
37
38type Evolvable<E extends Evolver> = { [P in keyof E]?: Evolved<E[P]>;
39};
40
41type Evolver<T extends Evolvable<any> = any> = { [key in keyof Partial<T>]: ((value: T[key]) => T[key]) | (T[key] extends Evolvable<any> ? Evolver<T[key]> : never);
42};
43
44type Evolve<O extends Evolvable<E>, E extends Evolver> = { [P in keyof O]: P extends keyof E
45 ? EvolveValue<O[P], E[P]>
46 : O[P];
47};
48
49type Evolved<A> =
50 A extends (value: infer V) => any
51 ? V
52 : A extends Evolver
53 ? Evolvable<A>
54 : never;
55
56type EvolveNestedValue<O, E extends Evolver> =
57 O extends object
58 ? O extends Evolvable<E>
59 ? Evolve<O, E>
60 : never
61 : never;
62
63type EvolveValue<V, E> =
64 E extends (value: V) => any
65 ? ReturnType<E>
66 : E extends Evolver
67 ? EvolveNestedValue<V, E>
68 : never;
69
70interface AssocPartialOne<K extends keyof any> {
71 <T>(val: T): <U>(obj: U) => Record<K, T> & U;
72 <T, U>(val: T, obj: U): Record<K, T> & U;
73}
74
75// RAMBDAX INTERFACES
76// ============================================
77type Func<T> = (input: any) => T;
78type VoidInputFunc<T> = () => T;
79type Fn<In, Out> = (x: In) => Out;
80type SortObjectPredicate<T> = (aProp: string, bProp: string, aValue: T, bValue: T) => number;
81
82type IdentityFunction<T> = (x: T) => T;
83
84interface Filter<T> {
85 (list: T[]): T[];
86 (obj: Dictionary<T>): Dictionary<T>;
87}
88
89type ArgumentTypes<T> = T extends (...args: infer U) => infer R ? U : never;
90type isfn<T> = (x: any, y: any) => T;
91
92interface Switchem<T> {
93 is: isfn<Switchem<T>>;
94 default: IdentityFunction<T>;
95}
96
97interface Schema {
98 [key: string]: any;
99}
100
101interface SchemaAsync {
102 [key: string]: Promise<boolean>;
103}
104
105interface IsValid {
106 input: object;
107 schema: Schema;
108}
109
110interface IsValidAsync {
111 input: object;
112 schema: Schema | SchemaAsync;
113}
114
115type ProduceRules<Output,K extends keyof Output, Input> = { [P in K]: (input: Input) => Output[P];
116};
117type ProduceAsyncRules<Output,K extends keyof Output, Input> = { [P in K]: (input: Input) => Promise<Output[P]>;
118};
119type ProduceAsyncRule<Input> = (input: Input) => Promise<any>;
120type Async<T> = (x: any) => Promise<T>;
121type AsyncIterable<T, K> = (x: T) => Promise<K>;
122type AsyncIterableIndexed<T, K> = (x: T, i: number) => Promise<K>;
123type AsyncPredicate<T> = (x: T) => Promise<boolean>;
124type AsyncPredicateIndexed<T> = (x: T, i: number) => Promise<boolean>;
125type AsyncWithProp<T> = (x: any, prop?: string) => Promise<T>;
126
127type ApplyDiffUpdate = {op:'update', path: string, value: any};
128type ApplyDiffAdd = {op:'add', path: string, value: any};
129type ApplyDiffRemove = {op:'remove', path: string};
130type ApplyDiffRule = ApplyDiffUpdate | ApplyDiffAdd | ApplyDiffRemove;
131
132
133/**
134 * It adds `a` and `b`.
135 */
136export function add(a: number, b: number): number;
137export function add(a: number): (b: number) => number;
138
139/**
140 * It replaces `index` in array `list` with the result of `replaceFn(list[i])`.
141 */
142export function adjust<T>(index: number, replaceFn: (x: T) => T, list: T[]): T[];
143export function adjust<T>(index: number, replaceFn: (x: T) => T): (list: T[]) => T[];
144
145/**
146 * It returns `true`, if all members of array `list` returns `true`, when applied as argument to `predicate` function.
147 */
148export function all<T>(predicate: (x: T) => boolean, list: T[]): boolean;
149export function all<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
150
151/**
152 * It returns `true`, if all functions of `predicates` return `true`, when `input` is their argument.
153 */
154export function allPass<T>(predicates: ((x: T) => boolean)[]): (input: T) => boolean;
155
156/**
157 * It returns function that always returns `x`.
158 */
159export function always<T>(x: T): (...args: unknown[]) => T;
160
161/**
162 * Logical AND
163 */
164export function and<T, U>(x: T, y: U): T | U;
165export function and<T>(x: T): <U>(y: U) => T | U;
166
167/**
168 * Logical OR
169 */
170export function or<T, U>(a: T, b: U): T | U;
171export function or<T>(a: T): <U>(b: U) => T | U;
172
173/**
174 * It returns `true`, if at least one member of `list` returns true, when passed to a `predicate` function.
175 */
176export function any<T>(predicate: (x: T) => boolean, list: T[]): boolean;
177export function any<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
178
179/**
180 * It accepts list of `predicates` and returns a function. This function with its `input` will return `true`, if any of `predicates` returns `true` for this `input`.
181 */
182export function anyPass<T>(predicates: SafePred<T>[]): SafePred<T>;
183
184/**
185 * It adds element `x` at the end of `list`.
186 */
187export function append<T>(x: T, list: T[]): T[];
188export function append<T>(x: T): <T>(list: T[]) => T[];
189
190export function applySpec<Spec extends Record<string, (...args: any[]) => any>>(
191 spec: Spec
192): (
193 ...args: Parameters<ValueOfRecord<Spec>>
194) => { [Key in keyof Spec]: ReturnType<Spec[Key]> };
195export function applySpec<T>(spec: any): (...args: any[]) => T;
196
197/**
198 * It makes a shallow clone of `obj` with setting or overriding the property `prop` with `newValue`.
199 */
200export function assoc<T, U, K extends string>(prop: K, val: T, obj: U): Record<K, T> & Omit<U, K>;
201export function assoc<T, K extends string>(prop: K, val: T): <U>(obj: U) => Record<K, T> & Omit<U, K>;
202export function assoc<K extends string>(prop: K): AssocPartialOne<K>;
203
204/**
205 * It makes a shallow clone of `obj` with setting or overriding with `newValue` the property found with `path`.
206 */
207export function assocPath<Output>(path: Path, newValue: any, obj: object): Output;
208export function assocPath<Output>(path: Path, newValue: any): (obj: object) => Output;
209export function assocPath<Output>(path: Path): (newValue: any) => (obj: object) => Output;
210
211/**
212 * It returns a function with `input` argument.
213 *
214 * This function will return `true`, if both `firstCondition` and `secondCondition` return `true` when `input` is passed as their argument.
215 */
216export function both(pred1: Pred, pred2: Pred): Pred;
217export function both<T>(pred1: Predicate<T>, pred2: Predicate<T>): Predicate<T>;
218export function both<T>(pred1: Predicate<T>): (pred2: Predicate<T>) => Predicate<T>;
219export function both(pred1: Pred): (pred2: Pred) => Pred;
220
221/**
222 * The method is also known as `flatMap`.
223 */
224export function chain<T, U>(fn: (n: T) => U[], list: T[]): U[];
225export function chain<T, U>(fn: (n: T) => U[]): (list: T[]) => U[];
226
227/**
228 * Restrict a number `input` to be within `min` and `max` limits.
229 *
230 * If `input` is bigger than `max`, then the result is `max`.
231 *
232 * If `input` is smaller than `min`, then the result is `min`.
233 */
234export function clamp(min: number, max: number, input: number): number;
235export function clamp(min: number, max: number): (input: number) => number;
236
237/**
238 * It creates a deep copy of the `input`, which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates.
239 */
240export function clone<T>(input: T): T;
241export function clone<T>(input: T[]): T[];
242
243/**
244 * It returns `inverted` version of `origin` function that accept `input` as argument.
245 *
246 * The return value of `inverted` is the negative boolean value of `origin(input)`.
247 */
248export function complement<T extends any[]>(predicate: (...args: T) => unknown): (...args: T) => boolean;
249
250/**
251 * It performs right-to-left function composition.
252 */
253export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
254 ...func: [
255 fnLast: (a: any) => TResult,
256 ...func: Array<(a: any) => any>,
257 f7: (a: R6) => R7,
258 f6: (a: R5) => R6,
259 f5: (a: R4) => R5,
260 f4: (a: R3) => R4,
261 f3: (a: R2) => R3,
262 f2: (a: R1) => R2,
263 f1: (...args: TArgs) => R1
264 ]
265): (...args: TArgs) => TResult; // fallback overload if number of composed functions greater than 7
266export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
267 f7: (a: R6) => R7,
268 f6: (a: R5) => R6,
269 f5: (a: R4) => R5,
270 f4: (a: R3) => R4,
271 f3: (a: R2) => R3,
272 f2: (a: R1) => R2,
273 f1: (...args: TArgs) => R1
274): (...args: TArgs) => R7;
275export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
276 f7: (a: R6) => R7,
277 f6: (a: R5) => R6,
278 f5: (a: R4) => R5,
279 f4: (a: R3) => R4,
280 f3: (a: R2) => R3,
281 f2: (a: R1) => R2,
282 f1: (...args: TArgs) => R1
283): (...args: TArgs) => R7;
284export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
285 f6: (a: R5) => R6,
286 f5: (a: R4) => R5,
287 f4: (a: R3) => R4,
288 f3: (a: R2) => R3,
289 f2: (a: R1) => R2,
290 f1: (...args: TArgs) => R1
291): (...args: TArgs) => R6;
292export function compose<TArgs extends any[], R1, R2, R3, R4, R5>(
293 f5: (a: R4) => R5,
294 f4: (a: R3) => R4,
295 f3: (a: R2) => R3,
296 f2: (a: R1) => R2,
297 f1: (...args: TArgs) => R1
298): (...args: TArgs) => R5;
299export function compose<TArgs extends any[], R1, R2, R3, R4>(
300 f4: (a: R3) => R4,
301 f3: (a: R2) => R3,
302 f2: (a: R1) => R2,
303 f1: (...args: TArgs) => R1
304): (...args: TArgs) => R4;
305export function compose<TArgs extends any[], R1, R2, R3>(
306 f3: (a: R2) => R3,
307 f2: (a: R1) => R2,
308 f1: (...args: TArgs) => R1
309): (...args: TArgs) => R3;
310export function compose<TArgs extends any[], R1, R2>(
311 f2: (a: R1) => R2,
312 f1: (...args: TArgs) => R1
313): (...args: TArgs) => R2;
314export function compose<TArgs extends any[], R1>(
315 f1: (...args: TArgs) => R1
316): (...args: TArgs) => R1;
317
318/**
319 * It returns a new string or array, which is the result of merging `x` and `y`.
320 */
321export function concat<T>(x: T[], y: T[]): T[];
322export function concat<T>(x: T[]): (y: T[]) => T[];
323export function concat(x: string, y: string): string;
324export function concat(x: string): (y: string) => string;
325
326/**
327 * It takes list with `conditions` and returns a new function `fn` that expects `input` as argument.
328 *
329 * This function will start evaluating the `conditions` in order to find the first winner(order of conditions matter).
330 *
331 * The winner is this condition, which left side returns `true` when `input` is its argument. Then the evaluation of the right side of the winner will be the final result.
332 *
333 * If no winner is found, then `fn` returns `undefined`.
334 */
335export function cond<T extends any[], R>(conditions: Array<CondPair<T, R>>): (...args: T) => R;
336
337/**
338 * Accepts a converging function and a list of branching functions and returns a new function. When invoked, this new function is applied to some arguments, each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value.
339 */
340export function converge(after: ((...a: any[]) => any), fns: ((...x: any[]) => any)[]): (...y: any[]) => any;
341
342/**
343 * It expects a function as input and returns its curried version.
344 */
345export function curry(fn: (...args: any[]) => any): (...a: any[]) => any;
346
347/**
348 * It returns a curried equivalent of the provided function, with the specified arity.
349 */
350export function curryN(length: number, fn: (...args: any[]) => any): (...a: any[]) => any;
351
352/**
353 * It decrements a number.
354 */
355export function dec(x: number): number;
356
357/**
358 * It returns `defaultValue`, if all of `inputArguments` are `undefined`, `null` or `NaN`.
359 *
360 * Else, it returns the first truthy `inputArguments` instance(from left to right).
361 */
362export function defaultTo<T>(defaultValue: T, input: T | null | undefined): T;
363export function defaultTo<T>(defaultValue: T): (input: T | null | undefined) => T;
364
365/**
366 * It returns the uniq set of all elements in the first list `a` not contained in the second list `b`.
367 *
368 * `R.equals` is used to determine equality.
369 */
370export function difference<T>(a: T[], b: T[]): T[];
371export function difference<T>(a: T[]): (b: T[]) => T[];
372
373/**
374 * It returns a new object that does not contain property `prop`.
375 */
376export function dissoc<T extends object, K extends keyof T>(prop: K, obj: T): Omit<T, K>;
377export function dissoc<K extends string | number>(prop: K): <T extends object>(obj: T) => Omit<T, K>;
378
379export function divide(x: number, y: number): number;
380export function divide(x: number): (y: number) => number;
381
382/**
383 * It returns `howMany` items dropped from beginning of list or string `input`.
384 */
385export function drop<T>(howMany: number, input: T[]): T[];
386export function drop(howMany: number, input: string): string;
387export function drop<T>(howMany: number): {
388 <T>(input: T[]): T[];
389 (input: string): string;
390};
391
392/**
393 * It returns `howMany` items dropped from the end of list or string `input`.
394 */
395export function dropLast<T>(howMany: number, input: T[]): T[];
396export function dropLast(howMany: number, input: string): string;
397export function dropLast<T>(howMany: number): {
398 <T>(input: T[]): T[];
399 (input: string): string;
400};
401
402/**
403 * It returns a new `predicate` function from `firstPredicate` and `secondPredicate` inputs.
404 *
405 * This `predicate` function will return `true`, if any of the two input predicates return `true`.
406 */
407export function either(firstPredicate: Pred, secondPredicate: Pred): Pred;
408export function either<T>(firstPredicate: Predicate<T>, secondPredicate: Predicate<T>): Predicate<T>;
409export function either<T>(firstPredicate: Predicate<T>): (secondPredicate: Predicate<T>) => Predicate<T>;
410export function either(firstPredicate: Pred): (secondPredicate: Pred) => Pred;
411
412/**
413 * When iterable is a string, then it behaves as `String.prototype.endsWith`.
414 * When iterable is a list, then it uses R.equals to determine if the target list ends in the same way as the given target.
415 */
416export function endsWith(target: string, iterable: string): boolean;
417export function endsWith(target: string): (iterable: string) => boolean;
418export function endsWith<T>(target: T[], list: T[]): boolean;
419export function endsWith<T>(target: T[]): (list: T[]) => boolean;
420
421/**
422 * It deeply compares `x` and `y` and returns `true` if they are equal.
423 */
424export function equals<T>(x: T, y: T): boolean;
425export function equals<T>(x: T): (y: T) => boolean;
426
427export function F(): boolean;
428
429/**
430 * It filters list or object `input` using a `predicate` function.
431 */
432export function filter<T>(predicate: Predicate<T>): (input: T[]) => T[];
433export function filter<T>(predicate: Predicate<T>, input: T[]): T[];
434export function filter<T, U>(predicate: ObjectPredicate<T>): (x: Dictionary<T>) => Dictionary<T>;
435export function filter<T>(predicate: ObjectPredicate<T>, x: Dictionary<T>): Dictionary<T>;
436
437/**
438 * It returns the first element of `list` that satisfy the `predicate`.
439 *
440 * If there is no such element, it returns `undefined`.
441 */
442export function find<T>(predicate: (x: T) => boolean, list: T[]): T | undefined;
443export function find<T>(predicate: (x: T) => boolean): (list: T[]) => T | undefined;
444
445/**
446 * It returns the index of the first element of `list` satisfying the `predicate` function.
447 *
448 * If there is no such element, then `-1` is returned.
449 */
450export function findIndex<T>(predicate: (x: T) => boolean, list: T[]): number;
451export function findIndex<T>(predicate: (x: T) => boolean): (list: T[]) => number;
452
453/**
454 * It returns the last element of `list` satisfying the `predicate` function.
455 *
456 * If there is no such element, then `undefined` is returned.
457 */
458export function findLast<T>(fn: (x: T) => boolean, list: T[]): T | undefined;
459export function findLast<T>(fn: (x: T) => boolean): (list: T[]) => T | undefined;
460
461/**
462 * It returns the index of the last element of `list` satisfying the `predicate` function.
463 *
464 * If there is no such element, then `-1` is returned.
465 */
466export function findLastIndex<T>(predicate: (x: T) => boolean, list: T[]): number;
467export function findLastIndex<T>(predicate: (x: T) => boolean): (list: T[]) => number;
468
469/**
470 * It deeply flattens an array.
471 */
472export function flatten<T>(list: any[]): T[];
473
474/**
475 * It returns function which calls `fn` with exchanged first and second argument.
476 */
477export function flip<T, U, TResult>(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult;
478
479/**
480 * It applies `iterable` function over all members of `list` and returns `list`.
481 */
482export function forEach<T>(fn: Iterator<T, void>, list: T[]): T[];
483export function forEach<T>(fn: Iterator<T, void>): (list: T[]) => T[];
484export function forEach<T>(fn: ObjectIterator<T, void>, list: Dictionary<T>): Dictionary<T>;
485export function forEach<T, U>(fn: ObjectIterator<T, void>): (list: Dictionary<T>) => Dictionary<T>;
486
487/**
488 * It transforms a `listOfPairs` to an object.
489 */
490export function fromPairs<V>(listOfPairs: ([number, V])[]): { [index: number]: V };
491export function fromPairs<V>(listOfPairs: ([string, V])[]): { [index: string]: V };
492
493/**
494 * It splits `list` according to a provided `groupFn` function and returns an object.
495 */
496export function groupBy<T>(groupFn: (x: T) => string, list: T[]): { [index: string]: T[] };
497export function groupBy<T>(groupFn: (x: T) => string): (list: T[]) => { [index: string]: T[] };
498export function groupBy<T, U>(groupFn: (x: T) => string, list: T[]): U;
499export function groupBy<T, U>(groupFn: (x: T) => string): (list: T[]) => U;
500
501/**
502 * It returns separated version of list or string `input`, where separation is done with equality `compareFn` function.
503 */
504export function groupWith<T>(compareFn: (x: T, y: T) => boolean): (input: T[]) => (T[])[];
505export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: T[]): (T[])[];
506export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: string): string[];
507
508/**
509 * It returns `true` if `obj` has property `prop`.
510 */
511export function has<T>(prop: string, obj: T): boolean;
512export function has(prop: string): <T>(obj: T) => boolean;
513
514/**
515 * It will return true, if `input` object has truthy `path`(calculated with `R.path`).
516 */
517export function hasPath<T>(
518 path: string | string[],
519 input: object
520): boolean;
521export function hasPath<T>(
522 path: string | string[]
523): (input: object) => boolean;
524
525/**
526 * It returns the first element of list or string `input`.
527 */
528export function head(input: string): string;
529export function head(emptyList: []): undefined;
530export function head<T>(input: T[]): T | undefined;
531
532/**
533 * It returns `true` if its arguments `a` and `b` are identical.
534 *
535 * Otherwise, it returns `false`.
536 */
537export function identical<T>(x: T, y: T): boolean;
538export function identical<T>(x: T): (y: T) => boolean;
539
540/**
541 * It just passes back the supplied `input` argument.
542 */
543export function identity<T>(input: T): T;
544
545/**
546 * It expects `condition`, `onTrue` and `onFalse` functions as inputs and it returns a new function with example name of `fn`.
547 *
548 * When `fn`` is called with `input` argument, it will return either `onTrue(input)` or `onFalse(input)` depending on `condition(input)` evaluation.
549 */
550export function ifElse<TArgs extends any[], TOnTrueResult, TOnFalseResult>(fn: (...args: TArgs) => boolean, onTrue: (...args: TArgs) => TOnTrueResult, onFalse: (...args: TArgs) => TOnFalseResult): (...args: TArgs) => TOnTrueResult | TOnFalseResult;
551
552/**
553 * It increments a number.
554 */
555export function inc(x: number): number;
556
557/**
558 * If `input` is string, then this method work as native `String.includes`.
559 *
560 * If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list.
561 */
562export function includes(valueToFind: string, input: string[] | string): boolean;
563export function includes(valueToFind: string): (input: string[] | string) => boolean;
564export function includes<T>(valueToFind: T, input: T[]): boolean;
565export function includes<T>(valueToFind: T): (input: T[]) => boolean;
566
567/**
568 * It generates object with properties provided by `condition` and values provided by `list` array.
569 *
570 * If `condition` is a function, then all list members are passed through it.
571 *
572 * If `condition` is a string, then all list members are passed through `R.path(condition)`.
573 */
574export function indexBy<T, K extends string | number = string>(condition: (key: T) => K, list: T[]): { [key in K]: T };
575export function indexBy<T, K extends string | number | undefined = string>(condition: (key: T) => K, list: T[]): { [key in NonNullable<K>]?: T };
576export function indexBy<T, K extends string | number = string>(condition: (key: T) => K): (list: T[]) => { [key in K]: T };
577export function indexBy<T, K extends string | number | undefined = string>(condition: (key: T) => K | undefined): (list: T[]) => { [key in NonNullable<K>]?: T };
578export function indexBy<T>(condition: string, list: T[]): { [key: string]: T };
579export function indexBy<T>(condition: string): (list: T[]) => { [key: string]: T };
580
581/**
582 * It returns the index of the first element of `list` equals to `valueToFind`.
583 *
584 * If there is no such element, it returns `-1`.
585 */
586export function indexOf<T>(valueToFind: T, list: T[]): number;
587export function indexOf<T>(valueToFind: T): (list: T[]) => number;
588
589/**
590 * It returns all but the last element of list or string `input`.
591 */
592export function init<T>(input: T[]): T[];
593export function init(input: string): string;
594
595/**
596 * It loops throw `listA` and `listB` and returns the intersection of the two according to `R.equals`.
597 */
598export function intersection<T>(listA: T[], listB: T[]): T[];
599export function intersection<T>(listA: T[]): (listB: T[]) => T[];
600
601/**
602 * It adds a `separator` between members of `list`.
603 */
604export function intersperse<T>(separator: T, list: T[]): T[];
605export function intersperse<T>(separator: T): (list: T[]) => T[];
606
607/**
608 * It returns `true` if `x` is instance of `targetPrototype`.
609 */
610export function is<C extends () => any>(targetPrototype: C, val: any): val is ReturnType<C>;
611export function is<C extends new () => any>(targetPrototype: C, val: any): val is InstanceType<C>;
612export function is<C extends () => any>(targetPrototype: C): (val: any) => val is ReturnType<C>;
613export function is<C extends new () => any>(targetPrototype: C): (val: any) => val is InstanceType<C>;
614
615/**
616 * It returns `true` if `x` is `empty`.
617 */
618export function isEmpty<T>(x: T): boolean;
619
620/**
621 * It returns `true` if `x` is either `null` or `undefined`.
622 */
623export function isNil(x: any): x is null | undefined;
624
625/**
626 * It returns a string of all `list` instances joined with a `glue`.
627 */
628export function join<T>(glue: string, list: T[]): string;
629export function join<T>(glue: string): (list: T[]) => string;
630
631/**
632 * It applies `Object.keys` over `x` and returns its keys.
633 */
634export function keys<T extends object>(x: T): (keyof T)[];
635export function keys<T>(x: T): string[];
636
637/**
638 * It returns the last element of `input`, as the `input` can be either a string or an array.
639 */
640export function last(str: string): string;
641export function last(emptyList: []): undefined;
642export function last<T extends any>(list: T[]): T | undefined;
643
644/**
645 * It returns the last index of `target` in `list` array.
646 *
647 * `R.equals` is used to determine equality between `target` and members of `list`.
648 *
649 * If there is no such index, then `-1` is returned.
650 */
651export function lastIndexOf<T>(target: T, list: T[]): number;
652export function lastIndexOf<T>(target: T): (list: T[]) => number;
653
654/**
655 * It returns the `length` property of list or string `input`.
656 */
657export function length<T>(input: T[]): number;
658
659/**
660 * It returns a `lens` for the given `getter` and `setter` functions.
661 *
662 * The `getter` **gets** the value of the focus; the `setter` **sets** the value of the focus.
663 *
664 * The setter should not mutate the data structure.
665 */
666export function lens<T, U, V>(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens;
667
668/**
669 * It returns a lens that focuses on specified `index`.
670 */
671export function lensIndex(index: number): Lens;
672
673/**
674 * It returns a lens that focuses on specified `path`.
675 */
676export function lensPath(path: RamdaPath): Lens;
677export function lensPath(path: string): Lens;
678
679/**
680 * It returns a lens that focuses on specified property `prop`.
681 */
682export function lensProp(prop: string): {
683 <T, U>(obj: T): U;
684 set<T, U, V>(val: T, obj: U): V;
685};
686
687/**
688 * It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
689 */
690export function over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
691export function over<T>(lens: Lens, fn: Arity1Fn, value: T[]): T[];
692export function over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
693export function over(lens: Lens, fn: Arity1Fn): <T>(value: T[]) => T[];
694export function over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
695export function over(lens: Lens): <T>(fn: Arity1Fn, value: T[]) => T[];
696
697/**
698 * It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
699 */
700export function set<T, U>(lens: Lens, replacer: U, obj: T): T;
701export function set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
702export function set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
703
704/**
705 * It returns the value of `lens` focus over `target` object.
706 */
707export function view<T, U>(lens: Lens): (target: T) => U;
708export function view<T, U>(lens: Lens, target: T): U;
709
710/**
711 * It returns the result of looping through `iterable` with `fn`.
712 *
713 * It works with both array and object.
714 */
715export function map<T, U>(fn: ObjectIterator<T, U>, iterable: Dictionary<T>): Dictionary<U>;
716export function map<T, U>(fn: Iterator<T, U>, iterable: T[]): U[];
717export function map<T, U>(fn: Iterator<T, U>): (iterable: T[]) => U[];
718export function map<T, U, S>(fn: ObjectIterator<T, U>): (iterable: Dictionary<T>) => Dictionary<U>;
719export function map<T>(fn: Iterator<T, T>): (iterable: T[]) => T[];
720export function map<T>(fn: Iterator<T, T>, iterable: T[]): T[];
721
722/**
723 * It works the same way as `R.map` does for objects. It is added as Ramda also has this method.
724 */
725export function mapObjIndexed<T>(fn: ObjectIterator<T, T>, iterable: Dictionary<T>): Dictionary<T>;
726export function mapObjIndexed<T, U>(fn: ObjectIterator<T, U>, iterable: Dictionary<T>): Dictionary<U>;
727export function mapObjIndexed<T>(fn: ObjectIterator<T, T>): (iterable: Dictionary<T>) => Dictionary<T>;
728export function mapObjIndexed<T, U>(fn: ObjectIterator<T, U>): (iterable: Dictionary<T>) => Dictionary<U>;
729
730/**
731 * Curried version of `String.prototype.match` which returns empty array, when there is no match.
732 */
733export function match(regExpression: RegExp, str: string): string[];
734export function match(regExpression: RegExp): (str: string) => string[];
735
736/**
737 * `R.mathMod` behaves like the modulo operator should mathematically, unlike the `%` operator (and by extension, `R.modulo`). So while `-17 % 5` is `-2`, `mathMod(-17, 5)` is `3`.
738 */
739export function mathMod(x: number, y: number): number;
740export function mathMod(x: number): (y: number) => number;
741
742/**
743 * It returns the greater value between `x` and `y`.
744 */
745export function max<T extends Ord>(x: T, y: T): T;
746export function max<T extends Ord>(x: T): (y: T) => T;
747
748/**
749 * It returns the greater value between `x` and `y` according to `compareFn` function.
750 */
751export function maxBy<T>(compareFn: (input: T) => Ord, x: T, y: T): T;
752export function maxBy<T>(compareFn: (input: T) => Ord, x: T): (y: T) => T;
753export function maxBy<T>(compareFn: (input: T) => Ord): (x: T) => (y: T) => T;
754
755/**
756 * It returns the mean value of `list` input.
757 */
758export function mean(list: number[]): number;
759
760/**
761 * It returns the median value of `list` input.
762 */
763export function median(list: number[]): number;
764
765/**
766 * It creates a copy of `target` object with overidden `newProps` properties.
767 */
768export function merge<A, B>(target: A, newProps: B): A & B
769export function merge<Output>(target: any): (newProps: any) => Output;
770
771/**
772 * It merges all objects of `list` array sequentially and returns the result.
773 */
774export function mergeAll<T>(list: object[]): T;
775export function mergeAll(list: object[]): object;
776
777/**
778 * Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects:
779 *
780 * - and both values are objects, the two values will be recursively merged
781 * - otherwise the value from the second object will be used.
782 */
783export function mergeDeepRight<Output>(target: object, newProps: object): Output;
784export function mergeDeepRight<Output>(target: object): (newProps: object) => Output;
785
786/**
787 * Same as `R.merge`, but in opposite direction.
788 */
789export function mergeLeft<Output>(newProps: object, target: object): Output;
790export function mergeLeft<Output>(newProps: object): (target: object) => Output;
791
792/**
793 * It returns the lesser value between `x` and `y`.
794 */
795export function min<T extends Ord>(x: T, y: T): T;
796export function min<T extends Ord>(x: T): (y: T) => T;
797
798/**
799 * It returns the lesser value between `x` and `y` according to `compareFn` function.
800 */
801export function minBy<T>(compareFn: (input: T) => Ord, x: T, y: T): T;
802export function minBy<T>(compareFn: (input: T) => Ord, x: T): (y: T) => T;
803export function minBy<T>(compareFn: (input: T) => Ord): (x: T) => (y: T) => T;
804
805/**
806 * Curried version of `x%y`.
807 */
808export function modulo(x: number, y: number): number;
809export function modulo(x: number): (y: number) => number;
810
811/**
812 * It returns a copy of `list` with exchanged `fromIndex` and `toIndex` elements.
813 */
814export function move<T>(fromIndex: number, toIndex: number, list: T[]): T[];
815export function move(fromIndex: number, toIndex: number): <T>(list: T[]) => T[];
816export function move(fromIndex: number): {
817 <T>(toIndex: number, list: T[]): T[];
818 (toIndex: number): <T>(list: T[]) => T[];
819};
820
821/**
822 * Curried version of `x*y`.
823 */
824export function multiply(x: number, y: number): number;
825export function multiply(x: number): (y: number) => number;
826
827export function negate(x: number): number;
828
829/**
830 * It returns `true`, if all members of array `list` returns `false`, when applied as argument to `predicate` function.
831 */
832export function none<T>(predicate: (x: T) => boolean, list: T[]): boolean;
833export function none<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
834
835/**
836 * It returns a boolean negated version of `input`.
837 */
838export function not(input: any): boolean;
839
840/**
841 * Curried version of `list[index]`.
842 */
843export function nth<T>(index: number, list: T[]): T | undefined;
844export function nth(index: number): <T>(list: T[]) => T | undefined;
845
846/**
847 * It creates an object with a single key-value pair.
848 */
849export function objOf<T, K extends string>(key: K, value: T): Record<K, T>;
850export function objOf<K extends string>(key: K): <T>(value: T) => Record<K, T>;
851
852/**
853 * It returns a function, which invokes only once `fn` function.
854 */
855export function once<T extends (...args: any[]) => any>(func: T): T;
856
857/**
858 * It returns a partial copy of an `obj` without `propsToOmit` properties.
859 */
860export function omit<T, K extends string>(propsToOmit: K[], obj: T): Omit<T, K>;
861export function omit<K extends string>(propsToOmit: K[]): <T>(obj: T) => Omit<T, K>;
862export function omit<T, U>(propsToOmit: string, obj: T): U;
863export function omit<T, U>(propsToOmit: string): (obj: T) => U;
864export function omit<T>(propsToOmit: string, obj: object): T;
865export function omit<T>(propsToOmit: string): (obj: object) => T;
866
867export function of<T>(x: T): T[];
868
869/**
870 * It is very similar to `R.curry`, but you can pass initial arguments when you create the curried function.
871 *
872 * `R.partial` will keep returning a function until all the arguments that the function `fn` expects are passed.
873 * The name comes from the fact that you partially inject the inputs.
874 */
875export function partial<V0, V1, T>(fn: (x0: V0, x1: V1) => T, args: [V0]): (x1: V1) => T;
876export function partial<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0, V1]): (x2: V2) => T;
877export function partial<V0, V1, V2, T>(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0]): (x1: V1, x2: V2) => T;
878export function partial<V0, V1, V2, V3, T>(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1, V2]): (x2: V3) => T;
879export function partial<V0, V1, V2, V3, T>(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1]): (x2: V2, x3: V3) => T;
880export function partial<V0, V1, V2, V3, T>(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0]): (x1: V1, x2: V2, x3: V3) => T;
881export function partial<T>(fn: (...a: any[]) => T, args: any[]): (...x: any[]) => T;
882
883/**
884 * It will return array of two objects/arrays according to `predicate` function. The first member holds all instances of `input` that pass the `predicate` function, while the second member - those who doesn't.
885 */
886export function partition<T>(
887 predicate: Predicate<T>,
888 input: T[]
889): [T[], T[]];
890export function partition<T>(
891 predicate: Predicate<T>
892): (input: T[]) => [T[], T[]];
893export function partition<T>(
894 predicate: (x: T, prop?: string) => boolean,
895 input: { [key: string]: T}
896): [{ [key: string]: T}, { [key: string]: T}];
897export function partition<T>(
898 predicate: (x: T, prop?: string) => boolean
899): (input: { [key: string]: T}) => [{ [key: string]: T}, { [key: string]: T}];
900
901/**
902 * If `pathToSearch` is `'a.b'` then it will return `1` if `obj` is `{a:{b:1}}`.
903 *
904 * It will return `undefined`, if such path is not found.
905 */
906export function path<Input, T>(pathToSearch: Path, obj: Input): T | undefined;
907export function path<T>(pathToSearch: Path, obj: any): T | undefined;
908export function path<T>(pathToSearch: Path): (obj: any) => T | undefined;
909export function path<Input, T>(pathToSearch: Path): (obj: Input) => T | undefined;
910
911/**
912 * It returns `true` if `pathToSearch` of `input` object is equal to `target` value.
913 *
914 * `pathToSearch` is passed to `R.path`, which means that it can be either a string or an array. Also equality between `target` and the found value is determined by `R.equals`.
915 */
916export function pathEq(pathToSearch: Path, target: any, input: any): boolean;
917export function pathEq(pathToSearch: Path, target: any): (input: any) => boolean;
918export function pathEq(pathToSearch: Path): (target: any) => (input: any) => boolean;
919
920/**
921 * It loops over members of `pathsToSearch` as `singlePath` and returns the array produced by `R.path(singlePath, obj)`.
922 *
923 * Because it calls `R.path`, then `singlePath` can be either string or a list.
924 */
925export function paths<Input, T>(pathsToSearch: Path[], obj: Input): (T | undefined)[];
926export function paths<Input, T>(pathsToSearch: Path[]): (obj: Input) => (T | undefined)[];
927export function paths<T>(pathsToSearch: Path[], obj: any): (T | undefined)[];
928export function paths<T>(pathsToSearch: Path[]): (obj: any) => (T | undefined)[];
929
930/**
931 * It reads `obj` input and returns either `R.path(pathToSearch, obj)` result or `defaultValue` input.
932 */
933export function pathOr<T>(defaultValue: T, pathToSearch: Path, obj: any): T;
934export function pathOr<T>(defaultValue: T, pathToSearch: Path): (obj: any) => T;
935export function pathOr<T>(defaultValue: T): (pathToSearch: Path) => (obj: any) => T;
936
937/**
938 * It returns a partial copy of an `input` containing only `propsToPick` properties.
939 *
940 * `input` can be either an object or an array.
941 *
942 * String anotation of `propsToPick` is one of the differences between `Rambda` and `Ramda`.
943 */
944export function pick<T, K extends string | number | symbol>(propsToPick: K[], input: T): Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
945export function pick<K extends string | number | symbol>(propsToPick: K[]): <T>(input: T) => Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
946export function pick<T, U>(propsToPick: string, input: T): U;
947export function pick<T, U>(propsToPick: string): (input: T) => U;
948export function pick<T>(propsToPick: string, input: object): T;
949export function pick<T>(propsToPick: string): (input: object) => T;
950
951/**
952 * Same as `R.pick` but it won't skip the missing props, i.e. it will assign them to `undefined`.
953 */
954export function pickAll<T, U>(propsToPick: string[], input: T): U;
955export function pickAll<T, U>(propsToPick: string[]): (input: T) => U;
956export function pickAll<T, U>(propsToPick: string, input: T): U;
957export function pickAll<T, U>(propsToPick: string): (input: T) => U;
958
959/**
960 * It performs left-to-right function composition.
961 */
962export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
963 ...funcs: [
964 f1: (...args: TArgs) => R1,
965 f2: (a: R1) => R2,
966 f3: (a: R2) => R3,
967 f4: (a: R3) => R4,
968 f5: (a: R4) => R5,
969 f6: (a: R5) => R6,
970 f7: (a: R6) => R7,
971 ...func: Array<(a: any) => any>,
972 fnLast: (a: any) => TResult
973 ]
974): (...args: TArgs) => TResult; // fallback overload if number of piped functions greater than 7
975export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7>(
976 f1: (...args: TArgs) => R1,
977 f2: (a: R1) => R2,
978 f3: (a: R2) => R3,
979 f4: (a: R3) => R4,
980 f5: (a: R4) => R5,
981 f6: (a: R5) => R6,
982 f7: (a: R6) => R7
983): (...args: TArgs) => R7;
984export function pipe<TArgs extends any[], R1, R2, R3, R4, R5, R6>(
985 f1: (...args: TArgs) => R1,
986 f2: (a: R1) => R2,
987 f3: (a: R2) => R3,
988 f4: (a: R3) => R4,
989 f5: (a: R4) => R5,
990 f6: (a: R5) => R6
991): (...args: TArgs) => R6;
992export function pipe<TArgs extends any[], R1, R2, R3, R4, R5>(
993 f1: (...args: TArgs) => R1,
994 f2: (a: R1) => R2,
995 f3: (a: R2) => R3,
996 f4: (a: R3) => R4,
997 f5: (a: R4) => R5
998): (...args: TArgs) => R5;
999export function pipe<TArgs extends any[], R1, R2, R3, R4>(
1000 f1: (...args: TArgs) => R1,
1001 f2: (a: R1) => R2,
1002 f3: (a: R2) => R3,
1003 f4: (a: R3) => R4
1004): (...args: TArgs) => R4;
1005export function pipe<TArgs extends any[], R1, R2, R3>(
1006 f1: (...args: TArgs) => R1,
1007 f2: (a: R1) => R2,
1008 f3: (a: R2) => R3
1009): (...args: TArgs) => R3;
1010export function pipe<TArgs extends any[], R1, R2>(
1011 f1: (...args: TArgs) => R1,
1012 f2: (a: R1) => R2
1013): (...args: TArgs) => R2;
1014export function pipe<TArgs extends any[], R1>(
1015 f1: (...args: TArgs) => R1
1016): (...args: TArgs) => R1;
1017
1018/**
1019 * It returns list of the values of `property` taken from the all objects inside `list`.
1020 */
1021export function pluck<K extends keyof T, T>(property: K, list: T[]): T[K][];
1022export function pluck<T>(property: number, list: { [k: number]: T }[]): T[];
1023export function pluck<P extends string>(property: P): <T>(list: Record<P, T>[]) => T[];
1024export function pluck(property: number): <T>(list: { [k: number]: T }[]) => T[];
1025
1026/**
1027 * It adds element `x` at the beginning of `list`.
1028 */
1029export function prepend<T>(x: T, input: T[]): T[];
1030export function prepend<T>(x: T): (input: T[]) => T[];
1031
1032export function product(list: number[]): number;
1033
1034/**
1035 * It returns the value of property `propToFind` in `obj`.
1036 *
1037 * If there is no such property, it returns `undefined`.
1038 */
1039export function prop<P extends keyof T, T>(propToFind: P, obj: T): T[P];
1040export function prop<P extends string | number>(p: P): <T>(propToFind: Record<P, T>) => T;
1041export function prop<P extends keyof T, T>(p: P): (propToFind: Record<P, T>) => T;
1042
1043/**
1044 * It returns true if `obj` has property `propToFind` and its value is equal to `valueToMatch`.
1045 */
1046export function propEq<K extends string | number>(propToFind: K, valueToMatch: any, obj: Record<K, any>): boolean;
1047export function propEq<K extends string | number>(propToFind: K, valueToMatch: any): (obj: Record<K, any>) => boolean;
1048export function propEq<K extends string | number>(propToFind: K): {
1049 (valueToMatch: any, obj: Record<K, any>): boolean;
1050 (valueToMatch: any): (obj: Record<K, any>) => boolean;
1051};
1052
1053/**
1054 * It returns `true` if `property` of `obj` is from `target` type.
1055 */
1056export function propIs<C extends (...args: any[]) => any, K extends keyof any>(type: C, name: K, obj: any): obj is Record<K, ReturnType<C>>;
1057export function propIs<C extends new (...args: any[]) => any, K extends keyof any>(type: C, name: K, obj: any): obj is Record<K, InstanceType<C>>;
1058export function propIs<C extends (...args: any[]) => any, K extends keyof any>(type: C, name: K): (obj: any) => obj is Record<K, ReturnType<C>>;
1059export function propIs<C extends new (...args: any[]) => any, K extends keyof any>(type: C, name: K): (obj: any) => obj is Record<K, InstanceType<C>>;
1060export function propIs<C extends (...args: any[]) => any>(type: C): {
1061 <K extends keyof any>(name: K, obj: any): obj is Record<K, ReturnType<C>>;
1062 <K extends keyof any>(name: K): (obj: any) => obj is Record<K, ReturnType<C>>;
1063};
1064export function propIs<C extends new (...args: any[]) => any>(type: C): {
1065 <K extends keyof any>(name: K, obj: any): obj is Record<K, InstanceType<C>>;
1066 <K extends keyof any>(name: K): (obj: any) => obj is Record<K, InstanceType<C>>;
1067};
1068
1069/**
1070 * It returns either `defaultValue` or the value of `property` in `obj`.
1071 */
1072export function propOr<T, P extends string>(defaultValue: T, property: P, obj: Partial<Record<P, T>> | undefined): T;
1073export function propOr<T, P extends string>(defaultValue: T, property: P): (obj: Partial<Record<P, T>> | undefined) => T;
1074export function propOr<T>(defaultValue: T): {
1075 <P extends string>(property: P, obj: Partial<Record<P, T>> | undefined): T;
1076 <P extends string>(property: P): (obj: Partial<Record<P, T>> | undefined) => T;
1077}
1078
1079/**
1080 * It returns list of numbers between `startInclusive` to `endExclusive` markers.
1081 */
1082export function range(startInclusive: number, endExclusive: number): number[];
1083export function range(startInclusive: number): (endExclusive: number) => number[];
1084
1085export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult, initialValue: TResult, list: T[]): TResult;
1086export function reduce<T, TResult>(reducer: (prev: TResult, current: T) => TResult, initialValue: TResult, list: T[]): TResult;
1087export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i?: number) => TResult): (initialValue: TResult, list: T[]) => TResult;
1088export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i?: number) => TResult, initialValue: TResult): (list: T[]) => TResult;
1089
1090/**
1091 * It has the opposite effect of `R.filter`.
1092 */
1093export function reject<T>(predicate: Predicate<T>, list: T[]): T[];
1094export function reject<T>(predicate: Predicate<T>): (list: T[]) => T[];
1095export function reject<T>(predicate: Predicate<T>, obj: Dictionary<T>): Dictionary<T>;
1096export function reject<T, U>(predicate: Predicate<T>): (obj: Dictionary<T>) => Dictionary<T>;
1097
1098export function repeat<T>(x: T): (timesToRepeat: number) => T[];
1099export function repeat<T>(x: T, timesToRepeat: number): T[];
1100
1101/**
1102 * It replaces `strOrRegex` found in `str` with `replacer`.
1103 */
1104export function replace(strOrRegex: RegExp | string, replacer: string, str: string): string;
1105export function replace(strOrRegex: RegExp | string, replacer: string): (str: string) => string;
1106export function replace(strOrRegex: RegExp | string): (replacer: string) => (str: string) => string;
1107
1108/**
1109 * It returns a reversed copy of list or string `input`.
1110 */
1111export function reverse<T>(input: T[]): T[];
1112export function reverse(input: string): string;
1113
1114export function slice(from: number, to: number, input: string): string;
1115export function slice<T>(from: number, to: number, input: T[]): T[];
1116export function slice(from: number, to: number): {
1117 (input: string): string;
1118 <T>(input: T[]): T[];
1119};
1120export function slice(from: number): {
1121 (to: number, input: string): string;
1122 <T>(to: number, input: T[]): T[];
1123};
1124
1125/**
1126 * It returns copy of `list` sorted by `sortFn` function.
1127 */
1128export function sort<T>(sortFn: (a: T, b: T) => number, list: T[]): T[];
1129export function sort<T>(sortFn: (a: T, b: T) => number): (list: T[]) => T[];
1130
1131/**
1132 * It returns copy of `list` sorted by `sortFn` function.
1133 */
1134export function sortBy<T>(sortFn: (a: T) => Ord, list: T[]): T[];
1135export function sortBy<T>(sortFn: (a: T) => Ord): (list: T[]) => T[];
1136export function sortBy(sortFn: (a: any) => Ord): <T>(list: T[]) => T[];
1137
1138/**
1139 * Curried version of `String.prototype.split`
1140 */
1141export function split(separator: string | RegExp): (str: string) => string[];
1142export function split(separator: string | RegExp, str: string): string[];
1143
1144/**
1145 * It splits `input` into slices of `sliceLength`.
1146 */
1147export function splitEvery<T>(sliceLength: number, input: T[]): (T[])[];
1148export function splitEvery(sliceLength: number, input: string): string[];
1149export function splitEvery(sliceLength: number): {
1150 (input: string): string[];
1151 <T>(input: T[]): (T[])[];
1152};
1153
1154/**
1155 * When iterable is a string, then it behaves as `String.prototype.startsWith`.
1156 * When iterable is a list, then it uses R.equals to determine if the target list starts in the same way as the given target.
1157 */
1158export function startsWith(target: string, str: string): boolean;
1159export function startsWith(target: string): (str: string) => boolean;
1160export function startsWith<T>(target: T[], list: T[]): boolean;
1161export function startsWith<T>(target: T[]): (list: T[]) => boolean;
1162
1163/**
1164 * Curried version of `x - y`
1165 */
1166export function subtract(x: number, y: number): number;
1167export function subtract(x: number): (y: number) => number;
1168
1169export function sum(list: number[]): number;
1170
1171/**
1172 * It returns a merged list of `x` and `y` with all equal elements removed.
1173 *
1174 * `R.equals` is used to determine equality.
1175 */
1176export function symmetricDifference<T>(x: T[], y: T[]): T[];
1177export function symmetricDifference<T>(x: T[]): <T>(y: T[]) => T[];
1178
1179export function T(): boolean;
1180
1181/**
1182 * It returns all but the first element of `input`.
1183 */
1184export function tail<T>(input: T[]): T[];
1185export function tail(input: string): string;
1186
1187/**
1188 * It returns the first `howMany` elements of `input`.
1189 */
1190export function take<T>(howMany: number, input: T[]): T[];
1191export function take(howMany: number, input: string): string;
1192export function take<T>(howMany: number): {
1193 <T>(input: T[]): T[];
1194 (input: string): string;
1195};
1196
1197/**
1198 * It returns the last `howMany` elements of `input`.
1199 */
1200export function takeLast<T>(howMany: number, input: T[]): T[];
1201export function takeLast(howMany: number, input: string): string;
1202export function takeLast<T>(howMany: number): {
1203 <T>(input: T[]): T[];
1204 (input: string): string;
1205};
1206
1207/**
1208 * It applies function `fn` to input `x` and returns `x`.
1209 *
1210 * One use case is debuging in the middle of `R.compose`.
1211 */
1212export function tap<T>(fn: (x: T) => void, input: T): T;
1213export function tap<T>(fn: (x: T) => void): (input: T) => T;
1214
1215/**
1216 * It determines whether `str` matches `regExpression`.
1217 */
1218export function test(regExpression: RegExp): (str: string) => boolean;
1219export function test(regExpression: RegExp, str: string): boolean;
1220
1221/**
1222 * It returns the result of applying function `fn` over members of range array.
1223 *
1224 * The range array includes numbers between `0` and `howMany`(exclusive).
1225 */
1226export function times<T>(fn: (i: number) => T, howMany: number): T[];
1227export function times<T>(fn: (i: number) => T): (howMany: number) => T[];
1228
1229export function toLower<S extends string>(str: S): Lowercase<S>;
1230export function toLower(str: string): string;
1231
1232export function toUpper<S extends string>(str: S): Uppercase<S>;
1233export function toUpper(str: string): string;
1234
1235/**
1236 * It transforms an object to a list.
1237 */
1238export function toPairs<O extends object, K extends Extract<keyof O, string | number>>(obj: O): Array<{ [key in K]: [`${key}`, O[key]] }[K]>;
1239export function toPairs<S>(obj: Record<string | number, S>): Array<[string, S]>;
1240
1241export function toString(x: unknown): string;
1242
1243export function transpose<T>(list: (T[])[]): (T[])[];
1244
1245export function trim(str: string): string;
1246
1247/**
1248 * It returns function that runs `fn` in `try/catch` block. If there was an error, then `fallback` is used to return the result. Note that `fn` can be value or asynchronous/synchronous function(unlike `Ramda` where fallback can only be a synchronous function).
1249 */
1250export function tryCatch<T, U>(
1251 fn: (input: T) => U,
1252 fallback: U
1253): (input: T) => U;
1254export function tryCatch<T, U>(
1255 fn: (input: T) => U,
1256 fallback: (input: T) => U
1257): (input: T) => U;
1258export function tryCatch<T>(
1259 fn: (input: any) => Promise<any>,
1260 fallback: T
1261): (input: any) => Promise<T>;
1262export function tryCatch<T>(
1263 fn: (input: any) => Promise<any>,
1264 fallback: (input: any) => Promise<any>,
1265): (input: any) => Promise<T>;
1266
1267/**
1268 * It accepts any input and it returns its type.
1269 */
1270export function type(x: any): RambdaTypes;
1271
1272/**
1273 * It takes two lists and return a new list containing a merger of both list with removed duplicates.
1274 *
1275 * `R.equals` is used to compare for duplication.
1276 */
1277export function union<T>(x: T[], y: T[]): T[];
1278export function union<T>(x: T[]): (y: T[]) => T[];
1279
1280/**
1281 * It returns a new array containing only one copy of each element of `list`.
1282 *
1283 * `R.equals` is used to determine equality.
1284 */
1285export function uniq<T>(list: T[]): T[];
1286
1287/**
1288 * It returns a new array containing only one copy of each element in `list` according to `predicate` function.
1289 *
1290 * This predicate should return true, if two elements are equal.
1291 */
1292export function uniqWith<T, U>(predicate: (x: T, y: T) => boolean, list: T[]): T[];
1293export function uniqWith<T, U>(predicate: (x: T, y: T) => boolean): (list: T[]) => T[];
1294
1295/**
1296 * The method returns function that will be called with argument `input`.
1297 *
1298 * If `predicate(input)` returns `false`, then the end result will be the outcome of `whenFalse(input)`.
1299 *
1300 * In the other case, the final output will be the `input` itself.
1301 */
1302export function unless<T, U>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => U, x: T): T | U;
1303export function unless<T, U>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => U): (x: T) => T | U;
1304export function unless<T>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => T, x: T): T;
1305export function unless<T>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => T): (x: T) => T;
1306
1307/**
1308 * It returns a copy of `list` with updated element at `index` with `newValue`.
1309 */
1310export function update<T>(index: number, newValue: T, list: T[]): T[];
1311export function update<T>(index: number, newValue: T): (list: T[]) => T[];
1312
1313/**
1314 * With correct input, this is nothing more than `Object.values(obj)`. If `obj` is not an object, then it returns an empty array.
1315 */
1316export function values<T extends object, K extends keyof T>(obj: T): T[K][];
1317
1318export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U, input: T): T | U;
1319export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U): (input: T) => T | U;
1320export function when<T, U>(predicate: (x: T) => boolean): ((whenTrueFn: (a: T) => U) => (input: T) => T | U);
1321
1322/**
1323 * It returns `true` if all each property in `conditions` returns `true` when applied to corresponding property in `input` object.
1324 */
1325export function where<T, U>(conditions: T, input: U): boolean;
1326export function where<T>(conditions: T): <U>(input: U) => boolean;
1327export function where<ObjFunc2, U>(conditions: ObjFunc2, input: U): boolean;
1328export function where<ObjFunc2>(conditions: ObjFunc2): <U>(input: U) => boolean;
1329
1330/**
1331 * It will return `true` if all of `input` object fully or partially include `rule` object.
1332 *
1333 * `R.equals` is used to determine equality.
1334 */
1335export function whereEq<T, U>(condition: T, input: U): boolean;
1336export function whereEq<T>(condition: T): <U>(input: U) => boolean;
1337
1338/**
1339 * It will return a new array, based on all members of `source` list that are not part of `matchAgainst` list.
1340 *
1341 * `R.equals` is used to determine equality.
1342 */
1343export function without<T>(matchAgainst: T[], source: T[]): T[];
1344export function without<T>(matchAgainst: T[]): (source: T[]) => T[];
1345
1346/**
1347 * Logical XOR
1348 */
1349export function xor(x: boolean, y: boolean): boolean;
1350export function xor(y: boolean): (y: boolean) => boolean;
1351
1352/**
1353 * It will return a new array containing tuples of equally positions items from both `x` and `y` lists.
1354 *
1355 * The returned list will be truncated to match the length of the shortest supplied list.
1356 */
1357export function zip<K, V>(x: K[], y: V[]): KeyValuePair<K, V>[];
1358export function zip<K>(x: K[]): <V>(y: V[]) => KeyValuePair<K, V>[];
1359
1360/**
1361 * It will return a new object with keys of `keys` array and values of `values` array.
1362 */
1363export function zipObj<T, K extends string>(keys: K[], values: T[]): { [P in K]: T };
1364export function zipObj<K extends string>(keys: K[]): <T>(values: T[]) => { [P in K]: T };
1365export function zipObj<T, K extends number>(keys: K[], values: T[]): { [P in K]: T };
1366export function zipObj<K extends number>(keys: K[]): <T>(values: T[]) => { [P in K]: T };
1367
1368/**
1369 * It takes list with properties `propsToPick` and returns a list with property values in `obj`.
1370 */
1371export function props<P extends string, T>(propsToPick: P[], obj: Record<P, T>): T[];
1372export function props<P extends string>(propsToPick: P[]): <T>(obj: Record<P, T>) => T[];
1373export function props<P extends string, T>(propsToPick: P[]): (obj: Record<P, T>) => T[];
1374
1375export function zipWith<T, U, TResult>(fn: (x: T, y: U) => TResult, list1: T[], list2: U[]): TResult[];
1376export function zipWith<T, U, TResult>(fn: (x: T, y: U) => TResult, list1: T[]): (list2: U[]) => TResult[];
1377export function zipWith<T, U, TResult>(fn: (x: T, y: U) => TResult): (list1: T[], list2: U[]) => TResult[];
1378
1379/**
1380 * It splits string or array at a given index.
1381 */
1382export function splitAt<T>(index: number, input: T[]): [T[], T[]];
1383export function splitAt(index: number, input: string): [string, string];
1384export function splitAt(index: number): {
1385 <T>(input: T[]): [T[], T[]];
1386 (input: string): [string, string];
1387};
1388
1389/**
1390 * It splits `list` to two arrays according to a `predicate` function.
1391 *
1392 * The first array contains all members of `list` before `predicate` returns `true`.
1393 */
1394export function splitWhen<T, U>(predicate: Predicate<T>, list: U[]): (U[])[];
1395export function splitWhen<T>(predicate: Predicate<T>): <U>(list: U[]) => (U[])[];
1396
1397export function takeLastWhile(predicate: (x: string) => boolean, input: string): string;
1398export function takeLastWhile(predicate: (x: string) => boolean): (input: string) => string;
1399export function takeLastWhile<T>(predicate: (x: T) => boolean, input: T[]): T[];
1400export function takeLastWhile<T>(predicate: (x: T) => boolean): <T>(input: T[]) => T[];
1401
1402/**
1403 * It takes object or array of functions as set of rules. These `rules` are applied to the `iterable` input to produce the result.
1404 */
1405export function evolve<T, U>(rules: ((x: T) => U)[], list: T[]): U[];
1406export function evolve<T, U>(rules: ((x: T) => U)[]) : (list: T[]) => U[];
1407export function evolve<E extends Evolver, V extends Evolvable<E>>(rules: E, obj: V): Evolve<V, E>;
1408export function evolve<E extends Evolver>(rules: E): <V extends Evolvable<E>>(obj: V) => Evolve<V, E>;
1409
1410export function dropLastWhile(predicate: (x: string) => boolean, iterable: string): string;
1411export function dropLastWhile(predicate: (x: string) => boolean): (iterable: string) => string;
1412export function dropLastWhile<T>(predicate: (x: T) => boolean, iterable: T[]): T[];
1413export function dropLastWhile<T>(predicate: (x: T) => boolean): <T>(iterable: T[]) => T[];
1414
1415/**
1416 * It removes any successive duplicates according to `R.equals`.
1417 */
1418export function dropRepeats<T>(list: T[]): T[];
1419
1420export function dropRepeatsWith<T>(predicate: (x: T, y: T) => boolean, list: T[]): T[];
1421export function dropRepeatsWith<T>(predicate: (x: T, y: T) => boolean): (list: T[]) => T[];
1422
1423export function dropWhile(fn: Predicate<string>, iterable: string): string;
1424export function dropWhile(fn: Predicate<string>): (iterable: string) => string;
1425export function dropWhile<T>(fn: Predicate<T>, iterable: T[]): T[];
1426export function dropWhile<T>(fn: Predicate<T>): (iterable: T[]) => T[];
1427
1428export function takeWhile(fn: Predicate<string>, iterable: string): string;
1429export function takeWhile(fn: Predicate<string>): (iterable: string) => string;
1430export function takeWhile<T>(fn: Predicate<T>, iterable: T[]): T[];
1431export function takeWhile<T>(fn: Predicate<T>): (iterable: T[]) => T[];
1432
1433/**
1434 * It returns `true` if property `prop` in `obj1` is equal to property `prop` in `obj2` according to `R.equals`.
1435 */
1436export function eqProps<T, U>(prop: string, obj1: T, obj2: U): boolean;
1437export function eqProps<P extends string>(prop: P): <T, U>(obj1: Record<P, T>, obj2: Record<P, U>) => boolean;
1438export function eqProps<T>(prop: string, obj1: T): <U>(obj2: U) => boolean;
1439
1440/**
1441 * It calls a function `fn` with the list of values of the returned function.
1442 *
1443 * `R.unapply` is the opposite of `R.apply` method.
1444 */
1445export function unapply<T = any>(fn: (args: any[]) => T): (...args: any[]) => T;
1446
1447/**
1448 * It applies function `fn` to the list of arguments.
1449 *
1450 * This is useful for creating a fixed-arity function from a variadic function. `fn` should be a bound function if context is significant.
1451 */
1452export function apply<T = any>(fn: (...args: any[]) => T, args: any[]): T;
1453export function apply<T = any>(fn: (...args: any[]) => T): (args: any[]) => T;
1454
1455/**
1456 * Creates a function that is bound to a context.
1457 */
1458export function bind<F extends (...args: any[]) => any, T>(fn: F, thisObj: T): (...args: Parameters<F>) => ReturnType<F>;
1459export function bind<F extends (...args: any[]) => any, T>(fn: F): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>;