From e8add0e478f8688b82f12263336905645fd8a191 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Mills Date: Sat, 7 Dec 2019 01:47:41 +0200 Subject: [PATCH] [ramda] cleanup (#40738) * chore: replace `Ensure` with `Clean` alias * chore: update ts-toolbelt * fix: return type of match * chore: moved type utilities to tools.d.ts * chore: move merge type utilities to tools * chore: move merge utilities + info header * chore: update ts-toolbelt * fix: lint, tool imports * fix: import * fix: comment lint * fix: lint * chore: move MergeAll * fix: export utility types * fix: lint * chore: flatten declaration * fix: typo * chore: remove references * chore: remove old project * chore: move references to OTHER_FILES.txt * chore: readme * fix: export global nsp --- types/ramda/OTHER_FILES.txt | 505 +++ types/ramda/README.md | 10 + types/ramda/index.d.ts | 5226 ++++++++++++------------------ types/ramda/package.json | 2 +- types/ramda/ramda-tests.ts | 7 +- types/ramda/test/filter-tests.ts | 7 +- types/ramda/test/maxBy-tests.ts | 3 +- types/ramda/test/minBy-tests.ts | 3 +- types/ramda/tools.d.ts | 436 ++- 9 files changed, 3062 insertions(+), 3137 deletions(-) create mode 100644 types/ramda/OTHER_FILES.txt diff --git a/types/ramda/OTHER_FILES.txt b/types/ramda/OTHER_FILES.txt new file mode 100644 index 0000000000..6c819533ba --- /dev/null +++ b/types/ramda/OTHER_FILES.txt @@ -0,0 +1,505 @@ +es/add.d.ts +es/addIndex.d.ts +es/adjust.d.ts +es/all.d.ts +es/allPass.d.ts +es/always.d.ts +es/and.d.ts +es/any.d.ts +es/anyPass.d.ts +es/ap.d.ts +es/aperture.d.ts +es/append.d.ts +es/apply.d.ts +es/applySpec.d.ts +es/applyTo.d.ts +es/ascend.d.ts +es/assoc.d.ts +es/assocPath.d.ts +es/binary.d.ts +es/bind.d.ts +es/both.d.ts +es/call.d.ts +es/chain.d.ts +es/clamp.d.ts +es/clone.d.ts +es/comparator.d.ts +es/complement.d.ts +es/compose.d.ts +es/composeK.d.ts +es/composeP.d.ts +es/composeWith.d.ts +es/concat.d.ts +es/cond.d.ts +es/construct.d.ts +es/constructN.d.ts +es/contains.d.ts +es/converge.d.ts +es/countBy.d.ts +es/curry.d.ts +es/curryN.d.ts +es/dec.d.ts +es/defaultTo.d.ts +es/descend.d.ts +es/difference.d.ts +es/differenceWith.d.ts +es/dissoc.d.ts +es/dissocPath.d.ts +es/divide.d.ts +es/drop.d.ts +es/dropLast.d.ts +es/dropLastWhile.d.ts +es/dropRepeats.d.ts +es/dropRepeatsWith.d.ts +es/either.d.ts +es/empty.d.ts +es/endsWith.d.ts +es/eqBy.d.ts +es/eqProps.d.ts +es/equals.d.ts +es/evolve.d.ts +es/F.d.ts +es/filter.d.ts +es/find.d.ts +es/findIndex.d.ts +es/findLast.d.ts +es/findLastIndex.d.ts +es/flatten.d.ts +es/flip.d.ts +es/forEach.d.ts +es/forEachObjIndexed.d.ts +es/fromPairs.d.ts +es/groupBy.d.ts +es/groupWith.d.ts +es/gt.d.ts +es/gte.d.ts +es/has.d.ts +es/hasIn.d.ts +es/hasPath.d.ts +es/head.d.ts +es/identical.d.ts +es/identity.d.ts +es/ifElse.d.ts +es/inc.d.ts +es/indexBy.d.ts +es/indexOf.d.ts +es/init.d.ts +es/innerJoin.d.ts +es/insertAll.d.ts +es/insert.d.ts +es/intersection.d.ts +es/intersectionWith.d.ts +es/intersperse.d.ts +es/into.d.ts +es/invert.d.ts +es/invertObj.d.ts +es/invoker.d.ts +es/is.d.ts +es/isEmpty.d.ts +es/isNil.d.ts +es/join.d.ts +es/juxt.d.ts +es/keys.d.ts +es/keysIn.d.ts +es/last.d.ts +es/lastIndexOf.d.ts +es/length.d.ts +es/lens.d.ts +es/lensIndex.d.ts +es/lensPath.d.ts +es/lensProp.d.ts +es/lift.d.ts +es/lt.d.ts +es/lte.d.ts +es/mapAccum.d.ts +es/mapAccumRight.d.ts +es/map.d.ts +es/mapObjIndexed.d.ts +es/match.d.ts +es/mathMod.d.ts +es/maxBy.d.ts +es/max.d.ts +es/mean.d.ts +es/median.d.ts +es/memoizeWith.d.ts +es/mergeAll.d.ts +es/mergeDeepLeft.d.ts +es/mergeDeepRight.d.ts +es/mergeDeepWith.d.ts +es/mergeDeepWithKey.d.ts +es/mergeLeft.d.ts +es/mergeRight.d.ts +es/merge.d.ts +es/mergeWith.d.ts +es/mergeWithKey.d.ts +es/minBy.d.ts +es/min.d.ts +es/modulo.d.ts +es/move.d.ts +es/multiply.d.ts +es/nAry.d.ts +es/negate.d.ts +es/none.d.ts +es/not.d.ts +es/nthArg.d.ts +es/nth.d.ts +es/o.d.ts +es/objOf.d.ts +es/of.d.ts +es/omit.d.ts +es/once.d.ts +es/or.d.ts +es/over.d.ts +es/otherwise.d.ts +es/pair.d.ts +es/partial.d.ts +es/partialRight.d.ts +es/partition.d.ts +es/path.d.ts +es/pathEq.d.ts +es/pathOr.d.ts +es/pathSatisfies.d.ts +es/pickAll.d.ts +es/pickBy.d.ts +es/pick.d.ts +es/pipe.d.ts +es/pipeK.d.ts +es/pipeP.d.ts +es/pipeWith.d.ts +es/pluck.d.ts +es/prepend.d.ts +es/product.d.ts +es/project.d.ts +es/prop.d.ts +es/propEq.d.ts +es/propIs.d.ts +es/propOr.d.ts +es/propSatisfies.d.ts +es/props.d.ts +es/range.d.ts +es/reduceBy.d.ts +es/reduced.d.ts +es/reduce.d.ts +es/reduceRight.d.ts +es/reduceWhile.d.ts +es/reject.d.ts +es/remove.d.ts +es/repeat.d.ts +es/replace.d.ts +es/reverse.d.ts +es/scan.d.ts +es/set.d.ts +es/slice.d.ts +es/sortBy.d.ts +es/sort.d.ts +es/sortWith.d.ts +es/splitAt.d.ts +es/split.d.ts +es/splitEvery.d.ts +es/splitWhen.d.ts +es/startsWith.d.ts +es/subtract.d.ts +es/sum.d.ts +es/symmetricDifference.d.ts +es/symmetricDifferenceWith.d.ts +es/tail.d.ts +es/take.d.ts +es/takeLast.d.ts +es/takeLastWhile.d.ts +es/takeWhile.d.ts +es/tap.d.ts +es/T.d.ts +es/test.d.ts +es/then.d.ts +es/thunkify.d.ts +es/times.d.ts +es/toLower.d.ts +es/toPairs.d.ts +es/toPairsIn.d.ts +es/toString.d.ts +es/toUpper.d.ts +es/transduce.d.ts +es/transpose.d.ts +es/traverse.d.ts +es/trim.d.ts +es/tryCatch.d.ts +es/type.d.ts +es/unapply.d.ts +es/unary.d.ts +es/uncurryN.d.ts +es/unfold.d.ts +es/union.d.ts +es/unionWith.d.ts +es/uniqBy.d.ts +es/uniq.d.ts +es/uniqWith.d.ts +es/unless.d.ts +es/unnest.d.ts +es/until.d.ts +es/update.d.ts +es/useWith.d.ts +es/values.d.ts +es/valuesIn.d.ts +es/view.d.ts +es/when.d.ts +es/where.d.ts +es/whereEq.d.ts +es/without.d.ts +es/xprod.d.ts +es/zip.d.ts +es/zipObj.d.ts +es/zipWith.d.ts +es/includes.d.ts + +src/add.d.ts +src/addIndex.d.ts +src/adjust.d.ts +src/all.d.ts +src/allPass.d.ts +src/always.d.ts +src/and.d.ts +src/any.d.ts +src/anyPass.d.ts +src/ap.d.ts +src/aperture.d.ts +src/append.d.ts +src/apply.d.ts +src/applySpec.d.ts +src/applyTo.d.ts +src/ascend.d.ts +src/assoc.d.ts +src/assocPath.d.ts +src/binary.d.ts +src/bind.d.ts +src/both.d.ts +src/call.d.ts +src/chain.d.ts +src/clamp.d.ts +src/clone.d.ts +src/comparator.d.ts +src/complement.d.ts +src/compose.d.ts +src/composeK.d.ts +src/composeP.d.ts +src/composeWith.d.ts +src/concat.d.ts +src/cond.d.ts +src/construct.d.ts +src/constructN.d.ts +src/contains.d.ts +src/converge.d.ts +src/countBy.d.ts +src/curry.d.ts +src/curryN.d.ts +src/dec.d.ts +src/defaultTo.d.ts +src/descend.d.ts +src/difference.d.ts +src/differenceWith.d.ts +src/dissoc.d.ts +src/dissocPath.d.ts +src/divide.d.ts +src/drop.d.ts +src/dropLast.d.ts +src/dropLastWhile.d.ts +src/dropRepeats.d.ts +src/dropRepeatsWith.d.ts +src/either.d.ts +src/empty.d.ts +src/endsWith.d.ts +src/eqBy.d.ts +src/eqProps.d.ts +src/equals.d.ts +src/evolve.d.ts +src/F.d.ts +src/filter.d.ts +src/find.d.ts +src/findIndex.d.ts +src/findLast.d.ts +src/findLastIndex.d.ts +src/flatten.d.ts +src/flip.d.ts +src/forEach.d.ts +src/forEachObjIndexed.d.ts +src/fromPairs.d.ts +src/groupBy.d.ts +src/groupWith.d.ts +src/gt.d.ts +src/gte.d.ts +src/has.d.ts +src/hasIn.d.ts +src/hasPath.d.ts +src/head.d.ts +src/identical.d.ts +src/identity.d.ts +src/ifElse.d.ts +src/inc.d.ts +src/indexBy.d.ts +src/indexOf.d.ts +src/init.d.ts +src/innerJoin.d.ts +src/insertAll.d.ts +src/insert.d.ts +src/intersection.d.ts +src/intersectionWith.d.ts +src/intersperse.d.ts +src/into.d.ts +src/invert.d.ts +src/invertObj.d.ts +src/invoker.d.ts +src/is.d.ts +src/isEmpty.d.ts +src/isNil.d.ts +src/join.d.ts +src/juxt.d.ts +src/keys.d.ts +src/keysIn.d.ts +src/last.d.ts +src/lastIndexOf.d.ts +src/length.d.ts +src/lens.d.ts +src/lensIndex.d.ts +src/lensPath.d.ts +src/lensProp.d.ts +src/lift.d.ts +src/lt.d.ts +src/lte.d.ts +src/mapAccum.d.ts +src/mapAccumRight.d.ts +src/map.d.ts +src/mapObjIndexed.d.ts +src/match.d.ts +src/mathMod.d.ts +src/maxBy.d.ts +src/max.d.ts +src/mean.d.ts +src/median.d.ts +src/memoizeWith.d.ts +src/mergeAll.d.ts +src/mergeDeepLeft.d.ts +src/mergeDeepRight.d.ts +src/mergeDeepWith.d.ts +src/mergeDeepWithKey.d.ts +src/mergeLeft.d.ts +src/mergeRight.d.ts +src/merge.d.ts +src/mergeWith.d.ts +src/mergeWithKey.d.ts +src/minBy.d.ts +src/min.d.ts +src/modulo.d.ts +src/move.d.ts +src/multiply.d.ts +src/nAry.d.ts +src/negate.d.ts +src/none.d.ts +src/not.d.ts +src/nthArg.d.ts +src/nth.d.ts +src/o.d.ts +src/objOf.d.ts +src/of.d.ts +src/omit.d.ts +src/once.d.ts +src/or.d.ts +src/over.d.ts +src/otherwise.d.ts +src/pair.d.ts +src/partial.d.ts +src/partialRight.d.ts +src/partition.d.ts +src/path.d.ts +src/pathEq.d.ts +src/pathOr.d.ts +src/pathSatisfies.d.ts +src/pickAll.d.ts +src/pickBy.d.ts +src/pick.d.ts +src/pipe.d.ts +src/pipeK.d.ts +src/pipeP.d.ts +src/pipeWith.d.ts +src/pluck.d.ts +src/prepend.d.ts +src/product.d.ts +src/project.d.ts +src/prop.d.ts +src/propEq.d.ts +src/propIs.d.ts +src/propOr.d.ts +src/propSatisfies.d.ts +src/props.d.ts +src/range.d.ts +src/reduceBy.d.ts +src/reduced.d.ts +src/reduce.d.ts +src/reduceRight.d.ts +src/reduceWhile.d.ts +src/reject.d.ts +src/remove.d.ts +src/repeat.d.ts +src/replace.d.ts +src/reverse.d.ts +src/scan.d.ts +src/set.d.ts +src/slice.d.ts +src/sortBy.d.ts +src/sort.d.ts +src/sortWith.d.ts +src/splitAt.d.ts +src/split.d.ts +src/splitEvery.d.ts +src/splitWhen.d.ts +src/startsWith.d.ts +src/subtract.d.ts +src/sum.d.ts +src/symmetricDifference.d.ts +src/symmetricDifferenceWith.d.ts +src/tail.d.ts +src/take.d.ts +src/takeLast.d.ts +src/takeLastWhile.d.ts +src/takeWhile.d.ts +src/tap.d.ts +src/T.d.ts +src/test.d.ts +src/then.d.ts +src/thunkify.d.ts +src/times.d.ts +src/toLower.d.ts +src/toPairs.d.ts +src/toPairsIn.d.ts +src/toString.d.ts +src/toUpper.d.ts +src/transduce.d.ts +src/transpose.d.ts +src/traverse.d.ts +src/trim.d.ts +src/tryCatch.d.ts +src/type.d.ts +src/unapply.d.ts +src/unary.d.ts +src/uncurryN.d.ts +src/unfold.d.ts +src/union.d.ts +src/unionWith.d.ts +src/uniqBy.d.ts +src/uniq.d.ts +src/uniqWith.d.ts +src/unless.d.ts +src/unnest.d.ts +src/until.d.ts +src/update.d.ts +src/useWith.d.ts +src/values.d.ts +src/valuesIn.d.ts +src/view.d.ts +src/when.d.ts +src/where.d.ts +src/whereEq.d.ts +src/without.d.ts +src/xprod.d.ts +src/zip.d.ts +src/zipObj.d.ts +src/zipWith.d.ts +src/includes.d.ts diff --git a/types/ramda/README.md b/types/ramda/README.md index d4182acd37..cdcad2d82d 100644 --- a/types/ramda/README.md +++ b/types/ramda/README.md @@ -6,6 +6,16 @@ **Please read this guide in its entirety.** Doing so helps ensure that the only breaking changes will be those that bring `@types/ramda` closer to representing the behavior of the underlying `ramda` package. +### Adding a new entry + +When a new function has been published by ramda + +- Add the function type to `index.d.ts` +- Add documentation for it, copied from ramda's website +- Add your entry import/re-export in `es` & `src` folders +- Add `es/` & `src/` to `OTHER_FILES.txt` +- Write some tests by following the instructions below + ### Tests Tests are located in the `test/` directory. Each ramda function has its own test file, named `-tests.ts`. When editing types for a function, please update the corresponding tests to prove that the behavior you seek actually works. When adding a new function, add a corresponding test file with as many tests as you can to detail the function's behavior. diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 3a50505399..1dd287863f 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for ramda 0.26 -// Project: https://github.com/donnut/typescript-ramda, https://ramdajs.com +// Project: https://ramdajs.com // Definitions by: Scott O'Malley // Erwin Poeze // Matt DeKrey @@ -33,3136 +33,2112 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.5 -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// +import * as _ from "ts-toolbelt"; +import { + Arity0Fn, + Arity1Fn, + Arity2Fn, + AssocPartialOne, + ComposeWithFns, + Dictionary, + Evolvable, + Evolve, + Evolver, + Filter, + Functor, + KeyValuePair, + Lens, + Merge, + MergeAll, + ObjPred, + Ord, + Path, + Placeholder, + Pred, + PipeWithFns, + Reduced, + SafePred, + ValueOfRecord, +} from "./tools"; -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// +export * from './tools'; -import { A, F, T, O } from "ts-toolbelt"; +/** + * Placeholder. When used with functions like curry, or op, the second argument is applied to the second + * position, and it returns a function waiting for its first argument. + */ +export const __: Placeholder; /* This is used in examples throughout the docs, but I it only seems to be directly explained here: https://ramdajs.com/0.9/docs/#op */ -declare let R: R.Static; +/** + * Adds two numbers (or strings). Equivalent to a + b but curried. + */ +export function add(a: number, b: number): number; +export function add(a: string, b: string): string; +export function add(a: number): (b: number) => number; +export function add(a: string): (b: string) => string; -declare namespace R { - import ValueOfRecord = Tools.ValueOfRecord; - type Omit = Pick>; +/** + * Creates a new list iteration function from an existing one by adding two new parameters to its callback + * function: the current index, and the entire list. + */ +export function addIndex(fn: (f: (item: T) => U, list: readonly T[]) => U[]): _.F.Curry<(a: (item: T, idx: number, list?: T[]) => U, b: readonly T[]) => U[]>; +/* Special case for forEach */ +export function addIndex(fn: (f: (item: T) => void, list: readonly T[]) => T[]): _.F.Curry<(a: (item: T, idx: number, list?: T[]) => void, b: readonly T[]) => T[]>; +/* Special case for reduce */ +export function addIndex(fn: (f: (acc: U, item: T) => U, aci: U, list: readonly T[]) => U): _.F.Curry<(a: (acc: U, item: T, idx: number, list?: T[]) => U, b: U, c: readonly T[]) => U>; - type Ord = number | string | boolean | Date; +/** + * Applies a function to the value at the given index of an array, returning a new copy of the array with the + * element at the given index replaced with the result of the function application. + */ +export function adjust(index: number, fn: (a: T) => T, list: readonly T[]): T[]; +export function adjust(index: number, fn: (a: T) => T): (list: readonly T[]) => T[]; - type Path = Array<(number | string)>; +/** + * Returns true if all elements of the list match the predicate, false if there are any that don't. + */ +export function all(fn: (a: T) => boolean, list: readonly T[]): boolean; +export function all(fn: (a: T) => boolean): (list: readonly T[]) => boolean; - type KeyValuePair = [K, V]; +/** + * Given a list of predicates, returns a new predicate that will be true exactly when all of them are. + */ +export function allPass(preds: readonly Pred[]): Pred; - interface Functor { - map(fn: (t: T) => U): Functor; +/** + * Returns a function that always returns the given value. + */ +export function always(val: T): () => T; + +/** + * A function that returns the first argument if it's falsy otherwise the second argument. Note that this is + * NOT short-circuited, meaning that if expressions are passed they are both evaluated. + */ +export function and any); } | number | boolean | string | null>(fn1: T, val2: any): boolean; +export function and any); } | number | boolean | string | null>(fn1: T): (val2: any) => boolean; + +/** + * Returns true if at least one of elements of the list match the predicate, false otherwise. + */ +export function any(fn: (a: T) => boolean, list: readonly T[]): boolean; +export function any(fn: (a: T) => boolean): (list: readonly T[]) => boolean; + +/** + * Given a list of predicates returns a new predicate that will be true exactly when any one of them is. + */ +export function anyPass(preds: Array>): SafePred; + +/** + * ap applies a list of functions to a list of values. + */ +export function ap(fns: Array<((a: T) => U)>, vs: readonly T[]): U[]; +export function ap(fns: Array<((a: T) => U)>): (vs: readonly T[]) => U[]; +export function ap( + fn: (x1: X1, x0: X0) => R, + fn1: (x1: X1) => X0 +): (x1: X1) => R; + +/** + * Returns a new list, composed of n-tuples of consecutive elements If n is greater than the length of the list, + * an empty list is returned. + */ +export function aperture(n: 1, list: readonly T[]): Array<[T]>; +export function aperture(n: 2, list: readonly T[]): Array<[T, T]>; +export function aperture(n: 3, list: readonly T[]): Array<[T, T, T]>; +export function aperture(n: 4, list: readonly T[]): Array<[T, T, T, T]>; +export function aperture(n: 5, list: readonly T[]): Array<[T, T, T, T, T]>; +export function aperture(n: 6, list: readonly T[]): Array<[T, T, T, T, T, T]>; +export function aperture(n: 7, list: readonly T[]): Array<[T, T, T, T, T, T, T]>; +export function aperture(n: 8, list: readonly T[]): Array<[T, T, T, T, T, T, T, T]>; +export function aperture(n: 9, list: readonly T[]): Array<[T, T, T, T, T, T, T, T, T]>; +export function aperture(n: 10, list: readonly T[]): Array<[T, T, T, T, T, T, T, T, T, T]>; +export function aperture(n: number, list: readonly T[]): T[][]; +export function aperture(n: number): (list: readonly T[]) => T[][]; + +/** + * Returns a new list containing the contents of the given list, followed by the given element. + */ +export function append(el: T, list: readonly T[]): T[]; +export function append(el: T): (list: readonly T[]) => T[]; + +/** + * Applies function fn to the argument list args. This is useful for creating a fixed-arity function from + * a variadic function. fn should be a bound function if context is significant. + */ +export function apply(fn: (arg0: T, ...args: readonly T[]) => TResult, args: readonly U[]): TResult; +export function apply(fn: (arg0: T, ...args: readonly T[]) => TResult): (args: readonly U[]) => TResult; + +/** + * Given a spec object recursively mapping properties to functions, creates a function producing an object + * of the same structure, by mapping each property to the result of calling its associated function with + * the supplied arguments. + */ +export function applySpec any>>( + obj: Obj +): ( + ...args: Parameters> +) => { [Key in keyof Obj]: ReturnType }; +export function applySpec(obj: any): (...args: readonly any[]) => T; + +/** + * Takes a value and applies a function to it. + * This function is also known as the thrush combinator. + */ +export function applyTo(el: T, fn: (t: T) => U): U; +export function applyTo(el: T): (fn: (t: T) => U) => U; + +/** + * Makes an ascending comparator function out of a function that returns a value that can be compared with < and >. + */ +export function ascend(fn: (obj: T) => any, a: T, b: T): number; +export function ascend(fn: (obj: T) => any): (a: T, b: T) => number; + +/** + * Makes a shallow clone of an object, setting or overriding the specified property with the given value. + */ +export function assoc(__: Placeholder, val: T, obj: U): (prop: K) => Record & U; +export function assoc(prop: K, __: Placeholder, obj: U): (val: T) => Record & U; +export function assoc(prop: K, val: T, obj: U): Record & U; +export function assoc(prop: K, val: T): (obj: U) => Record & U; +export function assoc(prop: K): AssocPartialOne; + +/** + * Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and + * placing the specific value at the tail end of that path. + */ +export function assocPath(__: Placeholder, val: T, obj: U): (path: Path) => U; +export function assocPath(path: Path, __: Placeholder, obj: U): (val: T) => U; +export function assocPath(path: Path, val: T, obj: U): U; +export function assocPath(path: Path, val: T): (obj: U) => U; +export function assocPath(path: Path): _.F.Curry<(a: T, b: U) => U>; + +/** + * Wraps a function of any arity (including nullary) in a function that accepts exactly 2 + * parameters. Any extraneous parameters will not be passed to the supplied function. + */ +export function binary(fn: (...args: readonly any[]) => any): (...a: readonly any[]) => any; + +/** + * Creates a function that is bound to a context. Note: R.bind does not provide the additional argument-binding + * capabilities of Function.prototype.bind. + */ +export function bind(fn: (...args: readonly any[]) => any, thisObj: T): (...args: readonly any[]) => any; + +/** + * A function wrapping calls to the two functions in an && operation, returning the result of the first function + * if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning + * that the second function will not be invoked if the first returns a false-y value. + */ +export function both(pred1: Pred, pred2: Pred): Pred; +export function both(pred1: Pred): (pred2: Pred) => Pred; + +/** + * Returns the result of calling its first argument with the remaining arguments. This is occasionally useful + * as a converging function for R.converge: the left branch can produce a function while the right branch + * produces a value to be passed to that function as an argument. + */ +export function call(fn: (...args: readonly any[]) => (...args: readonly any[]) => any, ...args: readonly any[]): any; + +/** + * `chain` maps a function over a list and concatenates the results. + * This implementation is compatible with the Fantasy-land Chain spec + */ +export function chain(fn: (n: T) => U[], list: readonly T[]): U[]; +export function chain(fn: (n: T) => U[]): (list: readonly T[]) => U[]; +export function chain(fn: (x0: X0, x1: X1) => R, fn1: (x1: X1) => X0): (x1: X1) => R; + +/** + * Restricts a number to be within a range. + * Also works for other ordered types such as Strings and Date + */ +export function clamp(min: T, max: T, value: T): T; +export function clamp(min: T, max: T): (value: T) => T; +export function clamp(min: T): (max: T, value: T) => T; +export function clamp(min: T): (max: T) => (value: T) => T; + +/** + * Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates. + */ +export function clone(value: T): T; +export function clone(value: readonly T[]): T[]; + +/** + * Makes a comparator function out of a function that reports whether the first element is less than the second. + */ +// comparator(pred: (a: any, b: any) => boolean): (x: number, y: number) => number; +export function comparator(pred: (a: T, b: T) => boolean): (x: T, y: T) => number; + +/** + * Takes a function f and returns a function g such that: + * - applying g to zero or more arguments will give true if applying the same arguments to f gives + * a logical false value; and + * - applying g to zero or more arguments will give false if applying the same arguments to f gives + * a logical true value. + */ +export function complement(pred: (...args: readonly any[]) => boolean): (...args: readonly any[]) => boolean; + +/** + * Performs right-to-left function composition. The rightmost function may have any arity; the remaining + * functions must be unary. + */ +// generic rest parameters in TS 3.0 allows writing a single variant for any number of Vx +// compose(fn0: (...args: V) => T1): (...args: V) => T1; +// compose(fn1: (x: T1) => T2, fn0: (...args: V) => T1): (...args: V) => T2; +// but requiring TS>=3.0 sounds like a breaking change, so just leaving a comment for the future +// tslint:disable:max-line-length +export function compose(fn0: () => T1): () => T1; +export function compose(fn0: (x0: V0) => T1): (x0: V0) => T1; +export function compose(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1; +export function compose(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1; + +export function compose(fn1: (x: T1) => T2, fn0: () => T1): () => T2; +export function compose(fn1: (x: T1) => T2, fn0: (x0: V0) => T1): (x0: V0) => T2; +export function compose(fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T2; +export function compose(fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T2; + +export function compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T3; +export function compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T3; +export function compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T3; +export function compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T3; + +export function compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T4; +export function compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T4; +export function compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T4; +export function compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T4; + +export function compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T5; +export function compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T5; +export function compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T5; +export function compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T5; + +export function compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T6; +export function compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T6; +export function compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T6; +export function compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6; +// tslint:enable:max-line-length + +/** + * Returns the right-to-left Kleisli composition of the provided functions, each of which must return a value of a type supported by chain. + * The typings only support arrays for now. + * All functions must be unary. + * R.composeK(h, g, f) is equivalent to R.compose(R.chain(h), R.chain(g), f). + * + * @deprecated since 0.26 in favor of composeWith(chain) + */ +// tslint:disable:max-line-length +export function composeK(fn0: (x0: V0) => T1[]): (x0: V0) => T1[]; +export function composeK(fn1: (x: T1) => T2[], fn0: (x0: V0) => T1[]): (x0: V0) => T2[]; +export function composeK(fn2: (x: T2) => T3[], fn1: (x: T1) => T2[], fn0: (x: V0) => T1[]): (x: V0) => T3[]; +export function composeK(fn3: (x: T3) => T4[], fn2: (x: T2) => T3[], fn1: (x: T1) => T2[], fn0: (x: V0) => T1[]): (x: V0) => T4[]; +export function composeK(fn4: (x: T4) => T5[], fn3: (x: T3) => T4[], fn2: (x: T2) => T3[], fn1: (x: T1) => T2[], fn0: (x: V0) => T1[]): (x: V0) => T5[]; +export function composeK(fn5: (x: T5) => T6[], fn4: (x: T4) => T5[], fn3: (x: T3) => T4[], fn2: (x: T2) => T3[], fn1: (x: T1) => T2[], fn0: (x: V0) => T1[]): (x: V0) => T6[]; +// tslint:enable:max-line-length + +/** + * Performs right-to-left composition of one or more Promise-returning functions. + * All functions must be unary. + * + * @deprecated since 0.26 in favor of composeWith(then) + */ +// tslint:disable:max-line-length +export function composeP(fn0: (x0: V0) => Promise): (x0: V0) => Promise; +export function composeP(fn1: (x: T1) => Promise, fn0: (x0: V0) => Promise): (x0: V0) => Promise; +export function composeP(fn2: (x: T2) => Promise, fn1: (x: T1) => Promise, fn0: (x: V0) => Promise): (x: V0) => Promise; +export function composeP(fn3: (x: T3) => Promise, fn2: (x: T2) => Promise, fn1: (x: T1) => Promise, fn0: (x: V0) => Promise): (x: V0) => Promise; +export function composeP(fn4: (x: T4) => Promise, fn3: (x: T3) => Promise, fn2: (x: T2) => Promise, fn1: (x: T1) => Promise, fn0: (x: V0) => Promise): (x: V0) => Promise; +export function composeP(fn5: (x: T5) => Promise, fn4: (x: T4) => Promise, fn3: (x: T3) => Promise, fn2: (x: T2) => Promise, fn1: (x: T1) => Promise, fn0: (x: V0) => Promise): (x: V0) => Promise; +// tslint:enable:max-line-length + +/** + * Performs right-to-left function composition using transforming function. + * With the current typings, all functions must be unary. + */ +export function composeWith(composer: (a: any) => any, fns: ComposeWithFns): (x0: V0) => T; +export function composeWith(composer: (a: any) => any): (fns: ComposeWithFns) => (x: V0) => T; + +/** + * Returns a new list consisting of the elements of the first list followed by the elements + * of the second. + */ +export function concat(placeholder: Placeholder): (list2: readonly T[], list1: readonly T[]) => T[]; +export function concat(placeholder: Placeholder, list2: readonly T[]): (list1: readonly T[]) => T[]; +export function concat(list1: readonly T[], list2: readonly T[]): T[]; +export function concat(list1: readonly T[]): (list2: readonly T[]) => T[]; +export function concat(list1: string, list2: string): string; +export function concat(list1: string): (list2: string) => string; + +/** + * Returns a function, fn, which encapsulates if/else-if/else logic. R.cond takes a list of [predicate, transform] pairs. + * All of the arguments to fn are applied to each of the predicates in turn until one returns a "truthy" value, at which + * point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates + * matches, fn returns undefined. + */ +export function cond(fns: Array<[Pred, (...a: readonly any[]) => any]>): (...a: readonly any[]) => any; +export function cond(fns: Array<[SafePred, (...a: readonly A[]) => B]>): (...a: readonly A[]) => B; + +/** + * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. + */ +export function construct(constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: A) => T; + +/** + * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. + * The arity of the function returned is specified to allow using variadic constructor functions. + */ +export function constructN(n: number, constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: Partial) => T; + +/** + * Returns `true` if the specified item is somewhere in the list, `false` otherwise. + * Equivalent to `indexOf(a)(list) > -1`. Uses strict (`===`) equality checking. + * + * @deprecated since 0.26 in favor of includes + */ +export function contains(__: Placeholder, list: string): (a: string) => boolean; +export function contains(__: Placeholder, list: readonly T[]): (a: T) => boolean; +export function contains(__: Placeholder): (list: string, a: string) => boolean; +export function contains(__: Placeholder): (list: readonly T[], a: T) => boolean; +export function contains(a: string, list: string): boolean; +export function contains(a: T, list: readonly T[]): boolean; +export function contains(a: string): (list: string) => boolean; +export function contains(a: T): (list: readonly T[]) => boolean; + +/** + * 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. + */ +export function converge(after: ((...a: readonly any[]) => any), fns: Array<((...a: readonly any[]) => any)>): (...a: readonly any[]) => any; + +/** + * Counts the elements of a list according to how many match each value + * of a key generated by the supplied function. Returns an object + * mapping the keys produced by `fn` to the number of occurrences in + * the list. Note that all keys are coerced to strings because of how + * JavaScript objects work. + */ +export function countBy(fn: (a: T) => string | number, list: readonly T[]): { [index: string]: number }; +export function countBy(fn: (a: T) => string | number): (list: readonly T[]) => { [index: string]: number }; + +/** + * Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. + * First, its arguments needn't be provided one at a time. + */ +export function curry any>(f: F): _.F.Curry; + +/** + * Returns a curried equivalent of the provided function, with the specified arity. The curried function has + * two unusual capabilities. First, its arguments needn't be provided one at a time. + */ +export function curryN(length: number, fn: (...args: readonly any[]) => any): (...a: readonly any[]) => any; + +/** + * Decrements its argument. + */ +export function dec(n: number): number; + +/** + * Returns the second argument if it is not null or undefined. If it is null or undefined, the + * first (default) argument is returned. + */ +export function defaultTo(a: T, b: U | null | undefined): T | U; +export function defaultTo(a: T): (b: U | null | undefined) => T | U; + +/** + * Makes a descending comparator function out of a function that returns a value that can be compared with < and >. + */ +export function descend(fn: (obj: T) => any, a: T, b: T): number; +export function descend(fn: (obj: T) => any): (a: T, b: T) => number; + +/** + * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. + */ +export function difference(list1: readonly T[], list2: readonly T[]): T[]; +export function difference(list1: readonly T[]): (list2: readonly T[]) => T[]; + +/** + * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. + * Duplication is determined according to the value returned by applying the supplied predicate to two list + * elements. + */ +export function differenceWith(pred: (a: T1, b: T2) => boolean, list1: readonly T1[], list2: readonly T2[]): T1[]; +export function differenceWith(pred: (a: T1, b: T2) => boolean): (list1: readonly T1[], list2: readonly T2[]) => T1[]; +export function differenceWith(pred: (a: T1, b: T2) => boolean, list1: readonly T1[]): (list2: readonly T2[]) => T1[]; + +/* + * Returns a new object that does not contain a prop property. + */ +// It seems impossible to infer the return type, so this may to be specified explicitely +export function dissoc(prop: string, obj: any): T; +export function dissoc(prop: string): (obj: any) => U; + +/** + * Makes a shallow clone of an object, omitting the property at the given path. + */ +export function dissocPath(path: Path, obj: any): T; +export function dissocPath(path: Path): (obj: any) => T; + +/** + * Divides two numbers. Equivalent to a / b. + */ +export function divide(__: Placeholder, b: number): (a: number) => number; +export function divide(__: Placeholder): (b: number, a: number) => number; +export function divide(a: number, b: number): number; +export function divide(a: number): (b: number) => number; + +/** + * Returns a new list containing all but the first n elements of the given list. + */ +export function drop(n: number, xs: readonly T[]): T[]; +export function drop(n: number, xs: string): string; +export function drop(n: number): { + (xs: string): string; + (xs: readonly T[]): T[]; +}; + +/** + * Returns a list containing all but the last n elements of the given list. + */ +export function dropLast(n: number, xs: readonly T[]): T[]; +export function dropLast(n: number, xs: string): string; +export function dropLast(n: number): { + (xs: readonly T[]): T[]; + (xs: string): string; +}; + +/** + * Returns a new list containing all but last then elements of a given list, passing each value from the + * right to the supplied predicate function, skipping elements while the predicate function returns true. + */ +export function dropLastWhile(fn: (a: T) => boolean, list: readonly T[]): T[]; +export function dropLastWhile(fn: (a: T) => boolean): (list: readonly T[]) => T[]; + +/** + * Returns a new list without any consecutively repeating elements. R.equals is used to determine equality. + */ +export function dropRepeats(list: readonly T[]): T[]; + +/** + * Returns a new list without any consecutively repeating elements. + * Equality is determined by applying the supplied predicate to each pair of consecutive elements. + * The first element in a series of equal elements will be preserved. + */ +export function dropRepeatsWith(predicate: (left: T, right: T) => boolean, list: readonly T[]): T[]; +export function dropRepeatsWith(predicate: (left: T, right: T) => boolean): (list: readonly T[]) => T[]; + +/** + * Returns a new list containing the last n elements of a given list, passing each value to the supplied + * predicate function, skipping elements while the predicate function returns true. + */ +export function dropWhile(fn: (a: T) => boolean, list: readonly T[]): T[]; +export function dropWhile(fn: (a: T) => boolean): (list: readonly T[]) => T[]; + +/** + * A function wrapping calls to the two functions in an || operation, returning the result of the first + * function if it is truth-y and the result of the second function otherwise. Note that this is + * short-circuited, meaning that the second function will not be invoked if the first returns a truth-y value. + */ +export function either(pred1: Pred, pred2: Pred): Pred; +export function either(pred1: Pred): (pred2: Pred) => Pred; + +/** + * Returns the empty value of its argument's type. Ramda defines the empty value of Array ([]), Object ({}), + * String (''), and Arguments. Other types are supported if they define .empty and/or .prototype.empty. + * Dispatches to the empty method of the first argument, if present. + */ +export function empty(x: T): T; + +/** + * Checks if a list ends with the provided values + */ +export function endsWith(a: string, list: string): boolean; +export function endsWith(a: string): (list: string) => boolean; +export function endsWith(a: T | readonly T[], list: readonly T[]): boolean; +export function endsWith(a: T | readonly T[]): (list: readonly T[]) => boolean; + +/** + * Takes a function and two values in its domain and returns true if the values map to the same value in the + * codomain; false otherwise. + */ +export function eqBy(fn: (a: T) => U, a: T, b: T): boolean; +export function eqBy(fn: (a: T) => U, a: T): (b: T) => boolean; +export function eqBy(fn: (a: T) => U): _.F.Curry<(a: T, b: T) => boolean>; + +/** + * Reports whether two functions have the same value for the specified property. + */ +export function eqProps(prop: string, obj1: T, obj2: U): boolean; +export function eqProps

(prop: P): (obj1: Record, obj2: Record) => boolean; - eqProps(prop: string, obj1: T): (obj2: U) => boolean; - - /** - * Returns true if its arguments are equivalent, false otherwise. Dispatches to an equals method if present. - * Handles cyclical data structures. - */ - equals(a: T, b: T): boolean; - equals(a: T): (b: T) => boolean; - - /** - * Creates a new object by evolving a shallow copy of object, according to the transformation functions. - */ - evolve>(transformations: E, obj: V): Evolve; - evolve(transformations: E): >(obj: V) => Evolve; - - /* - * A function that always returns false. Any passed in parameters are ignored. - */ - F(): boolean; - - /** - * Returns a new list containing only those items that match a given predicate function. The predicate function is passed one argument: (value). - */ - filter: Filter; - - /** - * Returns the first element of the list which matches the predicate, or `undefined` if no - * element matches. - */ - find(fn: (a: T) => boolean, list: readonly T[]): T | undefined; - find(fn: (a: T) => boolean): (list: readonly T[]) => T | undefined; - - /** - * Returns the index of the first element of the list which matches the predicate, or `-1` - * if no element matches. - */ - findIndex(fn: (a: T) => boolean, list: readonly T[]): number; - findIndex(fn: (a: T) => boolean): (list: readonly T[]) => number; - - /** - * Returns the last element of the list which matches the predicate, or `undefined` if no - * element matches. - */ - findLast(fn: (a: T) => boolean, list: readonly T[]): T | undefined; - findLast(fn: (a: T) => boolean): (list: readonly T[]) => T | undefined; - - /** - * Returns the index of the last element of the list which matches the predicate, or - * `-1` if no element matches. - */ - findLastIndex(fn: (a: T) => boolean, list: readonly T[]): number; - findLastIndex(fn: (a: T) => boolean): (list: readonly T[]) => number; - - /** - * Returns a new list by pulling every item out of it (and all its sub-arrays) and putting - * them in a new array, depth-first. - */ - flatten(list: T): T.Flatten; - - /** - * Returns a new function much like the supplied one, except that the first two arguments' - * order is reversed. - */ - flip(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult; - flip any, P extends F.Parameters>(fn: F): F.Curry<(...args: T.Merge<[P[1], P[0]], P>) => F.Return>; - - /** - * Iterate over an input list, calling a provided function fn for each element in the list. - */ - forEach(fn: (x: T) => void, list: readonly T[]): T[]; - forEach(fn: (x: T) => void): (list: readonly T[]) => T[]; - forEach(fn: (x: T) => void, list: readonly T[]): T[]; - forEach(fn: (x: T) => void): (list: readonly T[]) => T[]; - - /** - * Iterate over an input object, calling a provided function fn for each key and value in the object. - */ - forEachObjIndexed(fn: (value: T[keyof T], key: keyof T, obj: T) => void, obj: T): T; - forEachObjIndexed(fn: (value: T[keyof T], key: keyof T, obj: T) => void): (obj: T) => T; - - /** - * Creates a new object out of a list key-value pairs. - */ - fromPairs(pairs: Array>): { [index: string]: V }; - fromPairs(pairs: Array>): { [index: number]: V }; - - /** - * Splits a list into sublists stored in an object, based on the result of - * calling a String-returning function - * on each element, and grouping the results according to values returned. - */ - groupBy(fn: (a: T) => string, list: readonly T[]): { [index: string]: T[] }; - groupBy(fn: (a: T) => string): (list: readonly T[]) => { [index: string]: T[] }; - - /** - * Takes a list and returns a list of lists where each sublist's elements are all "equal" according to the provided equality function - */ - groupWith(fn: (x: T, y: T) => boolean): (list: readonly T[]) => T[][]; - groupWith(fn: (x: T, y: T) => boolean, list: readonly T[]): T[][]; - groupWith(fn: (x: T, y: T) => boolean, list: string): string[]; - - /** - * Returns true if the first parameter is greater than the second. - */ - gt(__: Placeholder, b: number): (a: number) => boolean; - gt(__: Placeholder): (b: number, a: number) => boolean; - gt(a: number, b: number): boolean; - gt(a: number): (b: number) => boolean; - - /** - * Returns true if the first parameter is greater than or equal to the second. - */ - gte(__: Placeholder, b: number): (a: number) => boolean; - gte(__: Placeholder): (b: number, a: number) => boolean; - gte(a: number, b: number): boolean; - gte(a: number): (b: number) => boolean; - - /** - * Returns whether or not an object has an own property with the specified name. - */ - has(__: Placeholder, obj: T): (s: string) => boolean; - has(__: Placeholder): (obj: T, s: string) => boolean; - has(s: string, obj: T): boolean; - has(s: string): (obj: T) => boolean; - - /** - * Returns whether or not an object or its prototype chain has a property with the specified name - */ - hasIn(s: string, obj: T): boolean; - hasIn(s: string): (obj: T) => boolean; - - /** - * Returns whether or not a path exists in an object. Only the object's own properties are checked. - */ - hasPath(list: readonly string[], obj: T): boolean; - hasPath(list: readonly string[]): (obj: T) => boolean; - - /** - * Returns the first element in a list. - * In some libraries this function is named `first`. - */ - head(str: string): string; - head(list: readonly []): undefined; - head(list: readonly T[]): T | undefined; - - /** - * Returns true if its arguments are identical, false otherwise. Values are identical if they reference the - * same memory. NaN is identical to NaN; 0 and -0 are not identical. - */ - identical(a: T, b: T): boolean; - identical(a: T): (b: T) => boolean; - - /** - * A function that does nothing but return the parameter supplied to it. Good as a default - * or placeholder function. - */ - identity(a: T): T; - - /** - * Creates a function that will process either the onTrue or the onFalse function depending upon the result - * of the condition predicate. - */ - ifElse(fn: Pred, onTrue: Arity1Fn, onFalse: Arity1Fn): Arity1Fn; - ifElse(fn: Pred, onTrue: Arity2Fn, onFalse: Arity2Fn): Arity2Fn; - - /** - * Increments its argument. - */ - inc(n: number): number; - - /** - * Given a target, this function checks a list for the target and returns a boolean. - * Given a string, this function checks for the string in another string or list and returns - * a boolean. - */ - includes(s: string, list: readonly string[] | string): boolean; - includes(s: string): (list: readonly string[] | string) => boolean; - includes(target: T, list: readonly T[]): boolean; - includes(target: T): (list: readonly T[]) => boolean; - - /** - * Given a function that generates a key, turns a list of objects into an object indexing the objects - * by the given key. - */ - indexBy(fn: (a: T) => string, list: readonly T[]): { [key: string]: T }; - indexBy(fn: (a: T) => string): (list: readonly T[]) => { [key: string]: T }; - - /** - * Returns the position of the first occurrence of an item in an array - * (by strict equality), - * or -1 if the item is not included in the array. - */ - indexOf(target: T, list: readonly T[]): number; - indexOf(target: T): (list: readonly T[]) => number; - - /** - * Returns all but the last element of a list or string. - */ - init(list: readonly T[]): T[]; - init(list: string): string; - - /** - * Takes a predicate `pred`, a list `xs`, and a list `ys`, and returns a list - * `xs'` comprising each of the elements of `xs` which is equal to one or more - * elements of `ys` according to `pred`. - * - * `pred` must be a binary function expecting an element from each list. - * - * `xs`, `ys`, and `xs'` are treated as sets, semantically, so ordering should - * not be significant, but since `xs'` is ordered the implementation guarantees - * that its values are in the same order as they appear in `xs`. Duplicates are - * not removed, so `xs'` may contain duplicates if `xs` contains duplicates. - */ - - innerJoin(pred: (a: T1, b: T2) => boolean, list1: readonly T1[], list2: readonly T2[]): T1[]; - innerJoin(pred: (a: T1, b: T2) => boolean): (list1: readonly T1[], list2: readonly T2[]) => T1[]; - innerJoin(pred: (a: T1, b: T2) => boolean, list1: readonly T1[]): (list2: readonly T2[]) => T1[]; - - /** - * Inserts the supplied element into the list, at index index. Note that - * this is not destructive: it returns a copy of the list with the changes. - */ - insert(index: number, elt: T, list: readonly T[]): T[]; - insert(index: number, elt: T): (list: readonly T[]) => T[]; - insert(index: number): (elt: T, list: readonly T[]) => T[]; - - /** - * Inserts the sub-list into the list, at index `index`. _Note that this - * is not destructive_: it returns a copy of the list with the changes. - */ - insertAll(index: number, elts: readonly T[], list: readonly T[]): T[]; - insertAll(index: number, elts: readonly T[]): (list: readonly T[]) => T[]; - insertAll(index: number): (elts: readonly T[], list: readonly T[]) => T[]; - - /** - * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists. - */ - intersection(list1: readonly T[], list2: readonly T[]): T[]; - intersection(list1: readonly T[]): (list2: readonly T[]) => T[]; - - /** - * Combines two lists into a set (i.e. no duplicates) composed of those - * elements common to both lists. Duplication is determined according - * to the value returned by applying the supplied predicate to two list - * elements. - */ - intersectionWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; - - /** - * Creates a new list with the separator interposed between elements. - */ - intersperse(separator: T, list: readonly T[]): T[]; - intersperse(separator: T): (list: readonly T[]) => T[]; - - /** - * Transforms the items of the list with the transducer and appends the transformed items to the accumulator - * using an appropriate iterator function based on the accumulator type. - */ - into(acc: any, xf: (...a: readonly any[]) => any, list: readonly T[]): T[]; - into(acc: any, xf: (...a: readonly any[]) => any): (list: readonly T[]) => T[]; - into(acc: any): (xf: (...a: readonly any[]) => any, list: readonly T[]) => T[]; - - /** - * Same as R.invertObj, however this accounts for objects with duplicate values by putting the values into an array. - */ - invert(obj: T): { [index: string]: string[] }; - - /** - * Returns a new object with the keys of the given object as values, and the values of the given object as keys. - */ - invertObj(obj: { [index: string]: string } | { [index: number]: string }): { [index: string]: string }; - - /** - * Turns a named method with a specified arity into a function that can be called directly - * supplied with arguments and a target object. - * - * The returned function is curried and accepts `arity + 1` parameters where the final - * parameter is the target object. - */ - invoker(arity: number, method: string): (...a: readonly any[]) => any; - - /** - * See if an object (`val`) is an instance of the supplied constructor. - * This function will check up the inheritance chain, if any. - */ - is(ctor: any, val: any): boolean; - is(ctor: any): (val: any) => boolean; - - /** - * Reports whether the list has zero elements. - */ - isEmpty(value: any): boolean; - - /** - * Checks if the input value is null or undefined. - */ - isNil(value: any): value is null | undefined; - - /** - * Returns a string made by inserting the `separator` between each - * element and concatenating all the elements into a single string. - */ - join(x: string, xs: readonly any[]): string; - join(x: string): (xs: readonly any[]) => string; - - /** - * Applies a list of functions to a list of values. - */ - juxt(fns: [(...a: A) => R1, (...a: A) => R2]): (...a: A) => [R1, R2]; - juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3]): (...a: A) => [R1, R2, R3]; - juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4]): (...a: A) => [R1, R2, R3, R4]; - juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4, (...a: A) => R5]): (...a: A) => [R1, R2, R3, R4, R5]; - juxt(fns: Array<(...args: A) => U>): (...args: A) => U[]; - - /** - * Returns a list containing the names of all the enumerable own - * properties of the supplied object. - */ - keys(x: T): Array; - keys(x: T): string[]; - - /** - * Returns a list containing the names of all the - * properties of the supplied object, including prototype properties. - */ - keysIn(obj: T): string[]; - - /** - * Returns the last element from a list. - */ - last(str: string): string; - last(list: readonly []): undefined; - last(list: readonly T[]): T | undefined; - - /** - * Returns the position of the last occurrence of an item (by strict equality) in - * an array, or -1 if the item is not included in the array. - */ - lastIndexOf(target: T, list: readonly T[]): number; - - /** - * Returns the number of elements in the array by returning list.length. - */ - length(list: readonly T[]): number; - - /** - * Returns a lens for the given getter and setter functions. The getter - * "gets" the value of the focus; the setter "sets" the value of the focus. - * The setter should not mutate the data structure. - */ - lens(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens; - - /** - * Creates a lens that will focus on index n of the source array. - */ - lensIndex(n: number): Lens; - - /** - * Returns a lens whose focus is the specified path. - * See also view, set, over. - */ - lensPath(path: Path): Lens; - - /** - * lensProp creates a lens that will focus on property k of the source object. - */ - lensProp(str: string): { - (obj: T): U; - set(val: T, obj: U): V; - /*map(fn: (...a: readonly any[]) => any, obj: T): T*/ - }; - - /** - * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other object that satisfies - * the FantasyLand Apply spec. - */ - lift(fn: ((...a: readonly any[]) => any), ...args: readonly any[]): any; - - /** - * "lifts" a function to be the specified arity, so that it may "map over" that many lists, Functions or other - * objects that satisfy the FantasyLand Apply spec. - */ - liftN(n: number, fn: ((...a: readonly any[]) => any), ...args: readonly any[]): any; - - /** - * Returns true if the first parameter is less than the second. - */ - lt(__: Placeholder, b: number): (a: number) => boolean; - lt(__: Placeholder): (b: number, a: number) => boolean; - lt(a: number, b: number): boolean; - lt(a: number): (b: number) => boolean; - - /** - * Returns true if the first parameter is less than or equal to the second. - */ - lte(__: Placeholder, b: number): (a: number) => boolean; - lte(__: Placeholder): (b: number, a: number) => boolean; - lte(a: number, b: number): boolean; - lte(a: number): (b: number) => boolean; - - /** - * Returns a new list, constructed by applying the supplied function to every element of the supplied list. - */ - map(fn: (x: T) => U, list: readonly T[]): U[]; - map(fn: (x: T) => U): (list: readonly T[]) => U[]; - map(fn: (x: T[keyof T & keyof U]) => U[keyof T & keyof U], list: T): U; - map(fn: (x: T[keyof T & keyof U]) => U[keyof T & keyof U]): (list: T) => U; - map(fn: (x: T) => U, obj: Functor): Functor; // used in functors - map(fn: (x: T) => U): (obj: Functor) => Functor; // used in functors - - /** - * The mapAccum function behaves like a combination of map and reduce. - */ - mapAccum(fn: (acc: U, value: T) => [U, TResult], acc: U, list: readonly T[]): [U, TResult[]]; - mapAccum(fn: (acc: U, value: T) => [U, TResult]): (acc: U, list: readonly T[]) => [U, TResult[]]; - mapAccum(fn: (acc: U, value: T) => [U, TResult], acc: U): (list: readonly T[]) => [U, TResult[]]; - - /** - * The mapAccumRight function behaves like a combination of map and reduce. - */ - mapAccumRight(fn: (acc: U, value: T) => [U, TResult], acc: U, list: readonly T[]): [U, TResult[]]; - mapAccumRight(fn: (acc: U, value: T) => [U, TResult]): (acc: U, list: readonly T[]) => [U, TResult[]]; - mapAccumRight(fn: (acc: U, value: T) => [U, TResult], acc: U): (list: readonly T[]) => [U, TResult[]]; - - /** - * Like mapObj, but but passes additional arguments to the predicate function. - */ - mapObjIndexed( - fn: (value: T, key: TKey, obj?: Record) => TResult, - obj: Record - ): Record; - mapObjIndexed( - fn: (value: T, key: TKey, obj?: Record) => TResult - ): (obj: Record) => Record; - mapObjIndexed( - fn: (value: T, key: string, obj?: { - [key: string]: T - }) => TResult, - obj: { - [key: string]: T - } - ): { - [key: string]: TResult - }; - mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult, obj: any): { [index: string]: TResult }; - mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult): (obj: any) => { [index: string]: TResult }; - - /** - * Tests a regular expression agains a String - */ - match(regexp: RegExp, str: string): any[]; - match(regexp: RegExp): (str: string) => any[]; - - /** - * 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. mathMod requires Integer arguments, and returns NaN - * when the modulus is zero or negative. - */ - mathMod(__: Placeholder, b: number): (a: number) => number; - mathMod(__: Placeholder): (b: number, a: number) => number; - mathMod(a: number, b: number): number; - mathMod(a: number): (b: number) => number; - - /** - * Returns the larger of its two arguments. - */ - max(a: T, b: T): T; - max(a: T): (b: T) => T; - - /** - * Takes a function and two values, and returns whichever value produces - * the larger result when passed to the provided function. - */ - maxBy(keyFn: (a: T) => Ord, a: T, b: T): T; - maxBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; - maxBy(keyFn: (a: T) => Ord): F.Curry<(a: T, b: T) => T>; - - /** - * Returns the mean of the given list of numbers. - */ - mean(list: readonly number[]): number; - - /** - * Returns the median of the given list of numbers. - */ - median(list: readonly number[]): number; - - /** - * Creates a new function that, when invoked, caches the result of calling fn for a given argument set and returns the result. - * Subsequent calls to the memoized fn with the same argument set will not result in an additional call to fn; instead, the cached result for that set of arguments will be returned. - */ - memoizeWith any>(keyFn: (...v: Parameters) => string, fn: T): T; - - /** - * Create a new object with the own properties of a - * merged with the own properties of object b. - * This function will *not* mutate passed-in objects. - * - * @deprecated since 0.26 in favor of mergeRight - */ - merge(__: Placeholder, b: O2): (a: O1) => O.Ensure>; - merge(__: Placeholder): (b: O2, a: O1) => O.Ensure>; - merge(a: O1, b: O2): O.Ensure>; - merge(a: O1): (b: O2) => O.Ensure>; - - /** - * Merges a list of objects together into one object. - */ - mergeAll(list: Os): O.AssignUp<{}, Os> extends infer M - ? {} extends M // nothing merged bcs no `as const` - ? T.UnionOf // so we output the default types - : O.Ensure // otherwise, we can compute `M` - : never; - - /** - * 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: - * and both values are objects, the two values will be recursively merged - * otherwise the value from the first object will be used. - */ - mergeDeepLeft(o1: O1, o2: O2): O.Ensure>; - mergeDeepLeft(o1: O1): (o2: O2) => O.Ensure>; - - /** - * 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: - * and both values are objects, the two values will be recursively merged - * otherwise the value from the second object will be used. - */ - mergeDeepRight(o1: O1, o2: O2): O.Ensure>; - mergeDeepRight(a: O1): (o2: O2) => O.Ensure>; - - /** - * Creates a new object with the own properties of the two provided objects. If a key exists in both objects: - * and both associated values are also objects then the values will be recursively merged. - * otherwise the provided function is applied to associated values using the resulting value as the new value - * associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object. - */ - mergeDeepWith(fn: (x: any, z: any) => any, a: T1, b: T2): any; - mergeDeepWith(fn: (x: any, z: any) => any, a: T1): (b: T2) => any; - mergeDeepWith(fn: (x: any, z: any) => any): (a: T1, b: T2) => any; - - /** - * Creates a new object with the own properties of the two provided objects. If a key exists in both objects: - * and both associated values are also objects then the values will be recursively merged. - * otherwise the provided function is applied to the key and associated values using the resulting value as - * the new value associated with the key. If a key only exists in one object, the value will be associated with - * the key of the resulting object. - */ - mergeDeepWithKey(fn: (k: string, x: any, z: any) => any, a: T1, b: T2): any; - mergeDeepWithKey(fn: (k: string, x: any, z: any) => any, a: T1): (b: T2) => any; - mergeDeepWithKey(fn: (k: string, x: any, z: any) => any): (a: T1, b: T2) => any; - - /** - * Create 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, the value from the first object will be used. - */ - mergeLeft(a: O1, b: O2): O.Ensure>; - mergeLeft(a: O1): (b: O2) => O.Ensure>; - - /** - * Create 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, the value from the second object will be used. - */ - mergeRight(a: O1, b: O2): O.Ensure>; - mergeRight(a: O1): (b: O2) => O.Ensure>; - - /** - * Creates a new object with the own properties of the two provided objects. If a key exists in both objects, - * the provided function is applied to the values associated with the key in each object, with the result being used as - * the value associated with the key in the returned object. The key will be excluded from the returned object if the - * resulting value is undefined. - */ - mergeWith(fn: (x: any, z: any) => any, a: U, b: V): any; - mergeWith(fn: (x: any, z: any) => any, a: U): (b: V) => any; - mergeWith(fn: (x: any, z: any) => any): (a: U, b: V) => any; - - /** - * Creates a new object with the own properties of the two provided objects. If a key exists in both objects, - * the provided function is applied to the key and the values associated with the key in each object, with the - * result being used as the value associated with the key in the returned object. The key will be excluded from - * the returned object if the resulting value is undefined. - */ - mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U, b: V): any; - mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U): (b: V) => any; - mergeWithKey(fn: (str: string, x: any, z: any) => any): (a: U, b: V) => any; - - /** - * Returns the smaller of its two arguments. - */ - min(a: T, b: T): T; - min(a: T): (b: T) => T; - - /** - * Takes a function and two values, and returns whichever value produces - * the smaller result when passed to the provided function. - */ - minBy(keyFn: (a: T) => Ord, a: T, b: T): T; - minBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; - minBy(keyFn: (a: T) => Ord): F.Curry<(a: T, b: T) => T>; - - /** - * Divides the second parameter by the first and returns the remainder. - * The flipped version (`moduloBy`) may be more useful curried. - * Note that this functions preserves the JavaScript-style behavior for - * modulo. For mathematical modulo see `mathMod` - */ - modulo(__: Placeholder, b: number): (a: number) => number; - modulo(__: Placeholder): (b: number, a: number) => number; - modulo(a: number, b: number): number; - modulo(a: number): (b: number) => number; - - /** - * Multiplies two numbers. Equivalent to a * b but curried. - */ - multiply(a: number, b: number): number; - multiply(a: number): (b: number) => number; - - /** - * Moves an item, at index `from`, to index `to`, in a `list` of elements. - * A new list will be created containing the new elements order. - */ - move(from: number, to: number, list: readonly T[]): T[]; - move(from: number, to: number): (list: readonly T[]) => T[]; - move(from: number): { - (to: number, list: readonly T[]): T[]; - (to: number): (list: readonly T[]) => T[]; - }; - - /** - * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. - * Any extraneous parameters will not be passed to the supplied function. - */ - nAry(n: number, fn: (...arg: readonly any[]) => any): (...a: readonly any[]) => any; - nAry(n: number): (fn: (...arg: readonly any[]) => any) => (...a: readonly any[]) => any; - - /** - * Negates its argument. - */ - negate(n: number): number; - - /** - * Returns true if no elements of the list match the predicate, false otherwise. - */ - none(fn: (a: T) => boolean, list: readonly T[]): boolean; - none(fn: (a: T) => boolean): (list: readonly T[]) => boolean; - - /** - * A function wrapping a call to the given function in a `!` operation. It will return `true` when the - * underlying function would return a false-y value, and `false` when it would return a truth-y one. - */ - not(value: any): boolean; - - /** - * Returns the nth element in a list. - */ - nth(n: number, list: readonly T[]): T | undefined; - nth(n: number): (list: readonly T[]) => T | undefined; - - /** - * Returns a function which returns its nth argument. - */ - nthArg(n: number): (...a: readonly any[]) => any; - - /** - * o is a curried composition function that returns a unary function. Like compose, o performs right-to-left function composition. - * Unlike compose, the rightmost function passed to o will be invoked with only one argument. - * Also, unlike compose, o is limited to accepting only 2 unary functions. - * The name o was chosen because of its similarity to the mathematical composition operator ∘. - */ - o(f: (x: T2) => R, g: (x: T1) => T2, v: T1): R; - o(f: (x: T2) => R, g: (x: T1) => T2): (v: T1) => R; - o( - f: (x: T2) => R, - ): { - (g: (x: T1) => T2, v: T1): R; - (g: (x: T1) => T2): (v: T1) => R; - }; - - /** - * Creates an object containing a single key:value pair. - */ - objOf(key: K, value: T): Record; - objOf(key: K): (value: T) => Record; - - /** - * Returns a singleton array containing the value provided. - */ - of(x: T): T[]; - - /** - * Returns a partial copy of an object omitting the keys specified. - */ - omit(names: readonly K[], obj: T): Omit; - omit(names: readonly K[]): (obj: T) => Omit; - - /** - * Accepts a function fn and returns a function that guards invocation of fn such that fn can only ever be - * called once, no matter how many times the returned function is invoked. The first value calculated is - * returned in subsequent invocations. - */ - once(fn: (...a: readonly any[]) => any): (...a: readonly any[]) => any; - once(fn: (...a: readonly any[]) => T): (...a: readonly any[]) => T; - - /** - * A function that returns the first truthy of two arguments otherwise the last argument. Note that this is - * NOT short-circuited, meaning that if expressions are passed they are both evaluated. - * Dispatches to the or method of the first argument if applicable. - */ - or(a: T, b: U): T | U; - or(a: T): (b: U) => T | U; - or any); }, U>(fn1: T, val2: U): T | U; - or any); }>(fn1: T): (val2: U) => T | U; - - /** - * Returns the result of applying the onFailure function to the value inside a failed promise. - * This is useful for handling rejected promises inside function compositions. - */ - otherwise(onError: (error: any) => B | Promise, promise: Promise): Promise; - otherwise(onError: (error: any) => B | Promise): (promise: Promise) => Promise; - - /** - * Returns the result of "setting" the portion of the given data structure - * focused by the given lens to the given value. - */ - over(lens: Lens, fn: Arity1Fn, value: T): T; - over(lens: Lens, fn: Arity1Fn, value: readonly T[]): T[]; - over(lens: Lens, fn: Arity1Fn): (value: T) => T; - over(lens: Lens, fn: Arity1Fn): (value: readonly T[]) => T[]; - over(lens: Lens): (fn: Arity1Fn, value: T) => T; - over(lens: Lens): (fn: Arity1Fn, value: readonly T[]) => T[]; - - /** - * Takes two arguments, fst and snd, and returns [fst, snd]. - */ - pair(fst: F, snd: S): [F, S]; - - /** - * Takes a function `f` and a list of arguments, and returns a function `g`. - * When applied, `g` returns the result of applying `f` to the arguments - * provided initially followed by the arguments provided to `g`. - */ - partial(fn: (x0: V0, x1: V1) => T, args: [V0]): (x1: V1) => T; - - partial(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0, V1]): (x2: V2) => T; - partial(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0]): (x1: V1, x2: V2) => T; - - partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1, V2]): (x2: V3) => T; - partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1]): (x2: V2, x3: V3) => T; - partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0]): (x1: V1, x2: V2, x3: V3) => T; - - partial(fn: (...a: readonly any[]) => T, args: readonly any[]): (...a: readonly any[]) => T; - - /** - * Takes a function `f` and a list of arguments, and returns a function `g`. - * When applied, `g` returns the result of applying `f` to the arguments - * provided to `g` followed by the arguments provided initially. - */ - partialRight(fn: (x0: V0, x1: V1) => T, args: [V1]): (x1: V0) => T; - - partialRight(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V1, V2]): (x2: V0) => T; - partialRight(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V2]): (x1: V0, x2: V1) => T; - - partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V1, V2, V3]): (x0: V0) => T; - partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V2, V3]): (x0: V0, x1: V1) => T; - partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V3]): (x0: V0, x1: V1, x2: V2) => T; - - partialRight(fn: (...a: readonly any[]) => T, args: readonly any[]): (...a: readonly any[]) => T; - - /** - * Takes a predicate and a list and returns the pair of lists of elements - * which do and do not satisfy the predicate, respectively. - */ - partition(fn: (a: string) => boolean, list: readonly string[]): [string[], string[]]; - partition(fn: (a: T) => boolean, list: readonly T[]): [T[], T[]]; - partition(fn: (a: T) => boolean): (list: readonly T[]) => [T[], T[]]; - partition(fn: (a: string) => boolean): (list: readonly string[]) => [string[], string[]]; - - /** - * Retrieve the value at a given path. - */ - path(path: Path, obj: any): T | undefined; - path(path: Path): (obj: any) => T | undefined; - - /** - * Determines whether a nested path on an object has a specific value, - * in `R.equals` terms. Most likely used to filter a list. - */ - pathEq(path: Path, val: any, obj: any): boolean; - pathEq(path: Path, val: any): (obj: any) => boolean; - pathEq(path: Path): F.Curry<(a: any, b: any) => boolean>; - - /** - * If the given, non-null object has a value at the given path, returns the value at that path. - * Otherwise returns the provided default value. - */ - pathOr(defaultValue: T, path: Path, obj: any): T; - pathOr(defaultValue: T, path: Path): (obj: any) => T; - pathOr(defaultValue: T): F.Curry<(a: Path, b: any) => T>; - - /** - * Returns true if the specified object property at given path satisfies the given predicate; false otherwise. - */ - pathSatisfies(pred: (val: T) => boolean, path: Path, obj: U): boolean; - pathSatisfies(pred: (val: T) => boolean, path: Path): (obj: U) => boolean; - pathSatisfies(pred: (val: T) => boolean): F.Curry<(a: Path, b: U) => boolean>; - - /** - * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the - * property is ignored. - */ - pick(names: readonly K[], obj: T): Pick>>; - pick(names: readonly K[]): (obj: T) => Pick>>; - - /** - * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist. - */ - pickAll(names: readonly string[], obj: T): U; - pickAll(names: readonly string[]): (obj: T) => U; - - /** - * Returns a partial copy of an object containing only the keys that satisfy the supplied predicate. - */ - pickBy(pred: ObjPred, obj: T): U; - pickBy(pred: ObjPred): (obj: T) => U; - - /** - * Creates a new function that runs each of the functions supplied as parameters in turn, - * passing the return value of each function invocation to the next function invocation, - * beginning with whatever arguments were passed to the initial invocation. - */ - pipe(fn0: () => T1): () => T1; - pipe(fn0: (x0: V0) => T1): (x0: V0) => T1; - pipe(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1; - - pipe(fn0: () => T1, fn1: (x: T1) => T2): () => T2; - pipe(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1) => T2; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1, x2: V2) => T2; - - pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): () => T3; - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x: V0) => T3; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x0: V0, x1: V1) => T3; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x0: V0, x1: V1, x2: V2) => T3; - - pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): () => T4; - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x: V0) => T4; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x0: V0, x1: V1) => T4; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x0: V0, x1: V1, x2: V2) => T4; - - pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): () => T5; - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x: V0) => T5; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x0: V0, x1: V1) => T5; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x0: V0, x1: V1, x2: V2) => T5; - - pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): () => T6; - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x: V0) => T6; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x0: V0, x1: V1) => T6; - pipe( - fn0: (x0: V0, x1: V1, x2: V2) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6): (x0: V0, x1: V1, x2: V2) => T6; - - pipe( - fn0: () => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn: (x: T6) => T7): () => T7; - pipe( - fn0: (x: V0) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn: (x: T6) => T7): (x: V0) => T7; - pipe( - fn0: (x0: V0, x1: V1) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7): (x0: V0, x1: V1) => T7; - pipe( - fn0: (x0: V0, x1: V1, x2: V2) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7): (x0: V0, x1: V1, x2: V2) => T7; - - pipe( - fn0: () => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn: (x: T7) => T8): () => T8; - pipe( - fn0: (x: V0) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn: (x: T7) => T8): (x: V0) => T8; - pipe( - fn0: (x0: V0, x1: V1) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8): (x0: V0, x1: V1) => T8; - pipe( - fn0: (x0: V0, x1: V1, x2: V2) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8): (x0: V0, x1: V1, x2: V2) => T8; - - pipe( - fn0: () => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9): () => T9; - pipe( - fn0: (x0: V0) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9): (x0: V0) => T9; - pipe( - fn0: (x0: V0, x1: V1) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9): (x0: V0, x1: V1) => T9; - pipe( - fn0: (x0: V0, x1: V1, x2: V2) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9): (x0: V0, x1: V1, x2: V2) => T9; - - pipe( - fn0: () => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9, - fn9: (x: T9) => T10): () => T10; - pipe( - fn0: (x0: V0) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9, - fn9: (x: T9) => T10): (x0: V0) => T10; - pipe( - fn0: (x0: V0, x1: V1) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9, - fn9: (x: T9) => T10): (x0: V0, x1: V1) => T10; - pipe( - fn0: (x0: V0, x1: V1, x2: V2) => T1, - fn1: (x: T1) => T2, - fn2: (x: T2) => T3, - fn3: (x: T3) => T4, - fn4: (x: T4) => T5, - fn5: (x: T5) => T6, - fn6: (x: T6) => T7, - fn7: (x: T7) => T8, - fn8: (x: T8) => T9, - fn9: (x: T9) => T10): (x0: V0, x1: V1, x2: V2) => T10; - - /** - * Returns the left-to-right Kleisli composition of the provided functions, each of which must return a value of a type supported by chain. - * The typings currently support arrays only as return values. - * All functions need to be unary. - * R.pipeK(f, g, h) is equivalent to R.pipe(f, R.chain(g), R.chain(h)). - * - * @deprecated since 0.26 in favor of pipeWith(chain) - */ - pipeK( - fn0: (x0: V0) => T1[]): (x0: V0) => T1[]; - pipeK( - fn0: (x0: V0) => T1[], - fn1: (x: T1) => T2[]): (x0: V0) => T2[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[]): (x: V0) => T3[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[]): (x: V0) => T4[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[]): (x: V0) => T5[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[], - fn5: (x: T5) => T6[]): (x: V0) => T6[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[], - fn5: (x: T5) => T6[], - fn: (x: T6) => T7[]): (x: V0) => T7[]; - pipeK( - fn0: (x: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[], - fn5: (x: T5) => T6[], - fn6: (x: T6) => T7[], - fn: (x: T7) => T8[]): (x: V0) => T8[]; - pipeK( - fn0: (x0: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[], - fn5: (x: T5) => T6[], - fn6: (x: T6) => T7[], - fn7: (x: T7) => T8[], - fn8: (x: T8) => T9[]): (x0: V0) => T9[]; - pipeK( - fn0: (x0: V0) => T1[], - fn1: (x: T1) => T2[], - fn2: (x: T2) => T3[], - fn3: (x: T3) => T4[], - fn4: (x: T4) => T5[], - fn5: (x: T5) => T6[], - fn6: (x: T6) => T7[], - fn7: (x: T7) => T8[], - fn8: (x: T8) => T9[], - fn9: (x: T9) => T10[]): (x0: V0) => T10[]; - - /** - * Performs left-to-right composition of one or more Promise-returning functions. - * All functions need to be unary. - * - * @deprecated since 0.26 in favor of pipeWith(then) - */ - pipeP( - fn0: (x0: V0) => Promise): (x0: V0) => Promise; - pipeP( - fn0: (x0: V0) => Promise, - fn1: (x: T1) => Promise): (x0: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise, - fn5: (x: T5) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise, - fn5: (x: T5) => Promise, - fn: (x: T6) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise, - fn5: (x: T5) => Promise, - fn6: (x: T6) => Promise, - fn: (x: T7) => Promise): (x: V0) => Promise; - pipeP( - fn0: (x0: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise, - fn5: (x: T5) => Promise, - fn6: (x: T6) => Promise, - fn7: (x: T7) => Promise, - fn8: (x: T8) => Promise): (x0: V0) => Promise; - pipeP( - fn0: (x0: V0) => Promise, - fn1: (x: T1) => Promise, - fn2: (x: T2) => Promise, - fn3: (x: T3) => Promise, - fn4: (x: T4) => Promise, - fn5: (x: T5) => Promise, - fn6: (x: T6) => Promise, - fn7: (x: T7) => Promise, - fn8: (x: T8) => Promise, - fn9: (x: T9) => Promise): (x0: V0) => Promise; - - /* - * Performs left-to-right function composition using transforming function. - * With the current typings, all functions must be unary. - */ - pipeWith(composer: (a: any) => any, fns: PipeWithFns): (x0: V0) => T; - pipeWith(composer: (a: any) => any): (fns: PipeWithFns) => (x0: V0) => T; - - /** - * Returns a new list by plucking the same named property off all objects in the list supplied. - */ - pluck(p: K, list: readonly T[]): Array; - pluck(p: number, list: Array<{ [k: number]: T }>): T[]; - pluck

(p: P): (list: Array>) => T[]; - pluck(p: number): (list: Array<{ [k: number]: T }>) => T[]; - - /** - * Returns a new list with the given element at the front, followed by the contents of the - * list. - */ - prepend(el: T, list: readonly T[]): T[]; - prepend(el: T): (list: readonly T[]) => T[]; - - /** - * Multiplies together all the elements of a list. - */ - product(list: readonly number[]): number; - - /** - * Reasonable analog to SQL `select` statement. - */ - project(props: readonly string[], objs: readonly T[]): U[]; - project(props: readonly string[]): (objs: readonly T[]) => U[]; - - /** - * Returns a function that when supplied an object returns the indicated property of that object, if it exists. - */ - prop(__: Placeholder, obj: T):

(p: P) => T[P]; - prop

(p: P, obj: T): T[P]; - prop

(p: P): (obj: Record) => T; - prop

(p: P): (obj: Record) => T; - - /** - * Determines whether the given property of an object has a specific - * value according to strict equality (`===`). Most likely used to - * filter a list. - */ - propEq(name: string | number, val: T, obj: any): boolean; - propEq(name: string | number, val: T): (obj: any) => boolean; - propEq(name: string | number): { - (val: T, obj: any): boolean; - (val: T): (obj: any) => boolean; - }; - - /** - * Returns true if the specified object property is of the given type; false otherwise. - */ - propIs(type: any, name: string, obj: any): boolean; - propIs(type: any, name: string): (obj: any) => boolean; - propIs(type: any): { - (name: string, obj: any): boolean; - (name: string): (obj: any) => boolean; - }; - - /** - * If the given, non-null object has an own property with the specified name, returns the value of that property. - * Otherwise returns the provided default value. - */ - propOr(val: T, __: Placeholder, obj: U): (p: string) => V; - propOr(__: Placeholder, p: string, obj: U): (val: T) => V; - propOr(val: T, p: string, obj: U): V; - propOr(val: T, p: string): (obj: U) => V; - propOr(val: T): (p: string, obj: U) => V; - - /** - * Returns the value at the specified property. - * The only difference from `prop` is the parameter order. - * Note: TS1.9 # replace any by dictionary - */ - props

(ps: readonly P[], obj: Record): T[]; - props

(ps: readonly P[]): (obj: Record) => T[]; - props

(ps: readonly P[]): (obj: Record) => T[]; - - /** - * Returns true if the specified object property satisfies the given predicate; false otherwise. - */ - propSatisfies(pred: (val: T) => boolean, name: string, obj: U): boolean; - propSatisfies(pred: (val: T) => boolean, name: string): (obj: U) => boolean; - propSatisfies(pred: (val: T) => boolean): F.Curry<(a: string, b: U) => boolean>; - - /** - * Returns a list of numbers from `from` (inclusive) to `to` - * (exclusive). In mathematical terms, `range(a, b)` is equivalent to - * the half-open interval `[a, b)`. - */ - range(from: number, to: number): number[]; - range(from: number): (to: number) => number[]; - - /** - * Returns a single item by iterating through the list, successively calling the iterator - * function and passing it an accumulator value and the current value from the array, and - * then passing the result to the next call. - */ - reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult, list: readonly T[]): TResult; - reduce(fn: (acc: TResult, elem: T) => TResult | Reduced): (acc: TResult, list: readonly T[]) => TResult; - reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult): (list: readonly T[]) => TResult; - - /** - * Groups the elements of the list according to the result of calling the String-returning function keyFn on each - * element and reduces the elements of each group to a single value via the reducer function valueFn. - */ - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string, list: readonly T[]): { [index: string]: TResult }; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string): (list: readonly T[]) => { [index: string]: TResult }; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult): F.Curry<(a: (elem: T) => string, b: readonly T[]) => { [index: string]: TResult }>; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult): F.Curry<(a: TResult, b: (elem: T) => string, c: readonly T[]) => { [index: string]: TResult }>; - - /** - * Returns a value wrapped to indicate that it is the final value of the reduce and - * transduce functions. The returned value should be considered a black box: the internal - * structure is not guaranteed to be stable. - */ - reduced(elem: T): Reduced; - - /** - * Returns a single item by iterating through the list, successively calling the iterator - * function and passing it an accumulator value and the current value from the array, and - * then passing the result to the next call. - */ - reduceRight(fn: (elem: T, acc: TResult) => TResult, acc: TResult, list: readonly T[]): TResult; - reduceRight(fn: (elem: T, acc: TResult) => TResult): (acc: TResult, list: readonly T[]) => TResult; - reduceRight(fn: (elem: T, acc: TResult) => TResult, acc: TResult): (list: readonly T[]) => TResult; - - /** - * Like reduce, reduceWhile returns a single item by iterating through the list, successively - * calling the iterator function. reduceWhile also takes a predicate that is evaluated before - * each step. If the predicate returns false, it "short-circuits" the iteration and returns - * the current value of the accumulator. - */ - reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult, acc: TResult, list: readonly T[]): TResult; - reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult, acc: TResult): (list: readonly T[]) => TResult; - reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult): F.Curry<(a: TResult, b: readonly T[]) => TResult>; - reduceWhile(predicate: (acc: TResult, elem: T) => boolean): F.Curry<(a: (acc: TResult, elem: T) => TResult, b: TResult, c: readonly T[]) => TResult>; - - /** - * Similar to `filter`, except that it keeps only values for which the given predicate - * function returns falsy. - */ - reject: Filter; - - /** - * Removes the sub-list of `list` starting at index `start` and containing `count` elements. - */ - remove(start: number, count: number, list: readonly T[]): T[]; - remove(start: number): (count: number, list: readonly T[]) => T[]; - remove(start: number, count: number): (list: readonly T[]) => T[]; - - /** - * Returns a fixed list of size n containing a specified identical value. - */ - repeat(a: T, n: number): T[]; - repeat(a: T): (n: number) => T[]; - - /** - * Replace a substring or regex match in a string with a replacement. - */ - replace(pattern: RegExp | string, replacement: string | ((match: string, ...args: readonly any[]) => string), str: string): string; - replace(pattern: RegExp | string, replacement: string | ((match: string, ...args: readonly any[]) => string)): (str: string) => string; - replace(pattern: RegExp | string): (replacement: string | ((match: string, ...args: readonly any[]) => string)) => (str: string) => string; - - /** - * Returns a new list with the same elements as the original list, just in the reverse order. - */ - reverse(list: readonly T[]): T[]; - /** - * Returns a new string with the characters in reverse order. - */ - reverse(str: string): string; - - /** - * Scan is similar to reduce, but returns a list of successively reduced values from the left. - */ - scan(fn: (acc: TResult, elem: T) => any, acc: TResult, list: readonly T[]): TResult[]; - scan(fn: (acc: TResult, elem: T) => any, acc: TResult): (list: readonly T[]) => TResult[]; - scan(fn: (acc: TResult, elem: T) => any): (acc: TResult, list: readonly T[]) => TResult[]; - - /** - * Returns the result of "setting" the portion of the given data structure focused by the given lens to the - * given value. - */ - set(lens: Lens, a: U, obj: T): T; - set(lens: Lens, a: U): (obj: T) => T; - set(lens: Lens): (a: U, obj: T) => T; - - /** - * Returns the elements from `xs` starting at `a` and ending at `b - 1`. - */ - slice(a: number, b: number, list: string): string; - slice(a: number, b: number, list: readonly T[]): T[]; - slice(a: number, b: number): { - (list: string): string; - (list: readonly T[]): T[]; - }; - slice(a: number): { - (b: number, list: string): string; - (b: number, list: readonly T[]): T[]; - }; - - /** - * Returns a copy of the list, sorted according to the comparator function, which should accept two values at a - * time and return a negative number if the first value is smaller, a positive number if it's larger, and zero - * if they are equal. - */ - sort(fn: (a: T, b: T) => number, list: readonly T[]): T[]; - sort(fn: (a: T, b: T) => number): (list: readonly T[]) => T[]; - - /** - * Sorts the list according to a key generated by the supplied function. - */ - sortBy(fn: (a: T) => Ord, list: readonly T[]): T[]; - sortBy(fn: (a: any) => Ord): (list: readonly T[]) => T[]; - - /** - * Sorts a list according to a list of comparators. - */ - sortWith(fns: Array<((a: T, b: T) => number)>, list: readonly T[]): T[]; - sortWith(fns: Array<((a: T, b: T) => number)>): (list: readonly T[]) => T[]; - - /** - * Splits a string into an array of strings based on the given - * separator. - */ - split(sep: string | RegExp): (str: string) => string[]; - split(sep: string | RegExp, str: string): string[]; - - /** - * Splits a given list or string at a given index. - */ - splitAt(index: number, list: readonly T[]): [T[], T[]]; - splitAt(index: number, list: string): [string, string]; - splitAt(index: number): { - (list: readonly T[]): [T[], T[]]; - (list: string): [string, string]; - }; - - /** - * Splits a collection into slices of the specified length. - */ - splitEvery(a: number, list: readonly T[]): T[][]; - splitEvery(a: number, list: string): string[]; - splitEvery(a: number): { - (list: string): string[]; - (list: readonly T[]): T[][]; - }; - - /** - * Takes a list and a predicate and returns a pair of lists with the following properties: - * - the result of concatenating the two output lists is equivalent to the input list; - * - none of the elements of the first output list satisfies the predicate; and - * - if the second output list is non-empty, its first element satisfies the predicate. - */ - splitWhen(pred: (val: T) => boolean, list: readonly U[]): U[][]; - splitWhen(pred: (val: T) => boolean): (list: readonly U[]) => U[][]; - - /** - * Checks if a list starts with the provided values - */ - startsWith(a: string, list: string): boolean; - startsWith(a: string): (list: string) => boolean; - startsWith(a: T | readonly T[], list: readonly T[]): boolean; - startsWith(a: T | readonly T[]): (list: readonly T[]) => boolean; - - /** - * Subtracts two numbers. Equivalent to `a - b` but curried. - */ - subtract(__: Placeholder, b: number): (a: number) => number; - subtract(__: Placeholder): (b: number, a: number) => number; - subtract(a: number, b: number): number; - subtract(a: number): (b: number) => number; - - /** - * Adds together all the elements of a list. - */ - sum(list: readonly number[]): number; - - /** - * Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. - */ - symmetricDifference(list1: readonly T[], list2: readonly T[]): T[]; - symmetricDifference(list: readonly T[]): (list: readonly T[]) => T[]; - - /** - * Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. - * Duplication is determined according to the value returned by applying the supplied predicate to two list elements. - */ - symmetricDifferenceWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; - symmetricDifferenceWith(pred: (a: T, b: T) => boolean): F.Curry<(a: readonly T[], b: readonly T[]) => T[]>; - - /** - * A function that always returns true. Any passed in parameters are ignored. - */ - T(): boolean; - - /** - * Returns all but the first element of a list or string. - */ - tail(list: string): string; - tail(list: readonly T[]): T[]; - - /** - * Returns a new list containing the first `n` elements of the given list. If - * `n > * list.length`, returns a list of `list.length` elements. - */ - take(n: number, xs: readonly T[]): T[]; - take(n: number, xs: string): string; - take(n: number): { - (xs: string): string; - (xs: readonly T[]): T[]; - }; - - /** - * Returns a new list containing the last n elements of the given list. If n > list.length, - * returns a list of list.length elements. - */ - takeLast(n: number, xs: readonly T[]): T[]; - takeLast(n: number, xs: string): string; - takeLast(n: number): { - (xs: readonly T[]): T[]; - (xs: string): string; - }; - - /** - * Returns a new list containing the last n elements of a given list, passing each value - * to the supplied predicate function, and terminating when the predicate function returns - * false. Excludes the element that caused the predicate function to fail. The predicate - * function is passed one argument: (value). - */ - takeLastWhile(pred: (a: T) => boolean, list: readonly T[]): T[]; - takeLastWhile(pred: (a: T) => boolean): (list: readonly T[]) => T[]; - - /** - * Returns a new list containing the first `n` elements of a given list, passing each value - * to the supplied predicate function, and terminating when the predicate function returns - * `false`. - */ - takeWhile(fn: (x: T) => boolean, list: readonly T[]): T[]; - takeWhile(fn: (x: T) => boolean): (list: readonly T[]) => T[]; - - /** - * The function to call with x. The return value of fn will be thrown away. - */ - tap(fn: (a: T) => any, value: T): T; - tap(fn: (a: T) => any): (value: T) => T; - - /** - * Determines whether a given string matches a given regular expression. - */ - test(regexp: RegExp, str: string): boolean; - test(regexp: RegExp): (str: string) => boolean; - - /** - * Returns the result of applying the onSuccess function to the value inside a successfully resolved promise. This is useful for working with promises inside function compositions. - */ - then(onSuccess: (a: A) => B | Promise, promise: Promise): Promise; - then(onSuccess: (a: A) => B | Promise): (promise: Promise) => Promise; - - /** - * Creates a thunk out of a function. - * A thunk delays a calculation until its result is needed, providing lazy evaluation of arguments. - */ - thunkify any>(fn: F): F.Curry<(...args: Parameters) => (() => ReturnType)>; - - /** - * Calls an input function `n` times, returning an array containing the results of those - * function calls. - */ - times(fn: (i: number) => T, n: number): T[]; - times(fn: (i: number) => T): (n: number) => T[]; - - /** - * The lower case version of a string. - */ - toLower(str: string): string; - - /** - * Converts an object into an array of key, value arrays. - * Only the object's own properties are used. - * Note that the order of the output array is not guaranteed to be - * consistent across different JS platforms. - */ - toPairs(obj: { [k: string]: S } | { [k: number]: S }): Array<[string, S]>; - - /** - * Converts an object into an array of key, value arrays. - * The object's own properties and prototype properties are used. - * Note that the order of the output array is not guaranteed to be - * consistent across different JS platforms. - */ - toPairsIn(obj: { [k: string]: S } | { [k: number]: S }): Array<[string, S]>; - - /** - * Returns the string representation of the given value. eval'ing the output should - * result in a value equivalent to the input value. Many of the built-in toString - * methods do not satisfy this requirement. - * - * If the given value is an [object Object] with a toString method other than - * Object.prototype.toString, this method is invoked with no arguments to produce the - * return value. This means user-defined constructor functions can provide a suitable - * toString method. - */ - toString(val: T): string; - - /** - * The upper case version of a string. - */ - toUpper(str: string): string; - - /** - * Initializes a transducer using supplied iterator function. Returns a single item by iterating through the - * list, successively calling the transformed iterator function and passing it an accumulator value and the - * current value from the array, and then passing the result to the next call. - */ - transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[], acc: readonly T[], list: readonly T[]): U; - transduce(xf: (arg: readonly T[]) => T[]): (fn: (acc: readonly U[], val: U) => U[], acc: readonly T[], list: readonly T[]) => U; - transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[]): (acc: readonly T[], list: readonly T[]) => U; - transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[], acc: readonly T[]): (list: readonly T[]) => U; - - /** - * Transposes the rows and columns of a 2D list. When passed a list of n lists of length x, returns a list of x lists of length n. - */ - transpose(list: readonly T[][]): T[][]; - - /** - * Maps an Applicative-returning function over a Traversable, then uses - * sequence to transform the resulting Traversable of Applicative into - * an Applicative of Traversable. - */ - traverse(of: (a: B) => B[], fn: (t: A) => B[], list: readonly A[]): B[][]; - traverse(of: (a: B) => B[], fn: (t: A) => B[]): (list: readonly A[]) => B[][]; - traverse(of: (a: B) => B[]): (fn: (t: A) => B[], list: readonly A[]) => B[][]; - - /** - * Removes (strips) whitespace from both ends of the string. - */ - trim(str: string): string; - - /** - * tryCatch takes two functions, a tryer and a catcher. The returned function evaluates the tryer; if it does - * not throw, it simply returns the result. If the tryer does throw, the returned function evaluates the catcher - * function and returns its result. Note that for effective composition with this function, both the tryer and - * catcher functions must return the same type of results. - */ - tryCatch(tryer: (...args: readonly any[]) => T, catcher: (...args: readonly any[]) => T): (...args: readonly any[]) => T; - - /** - * Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', - * 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them - * all as 'Object'. - */ - type(val: any): 'Object' | 'Number' | 'Boolean' | 'String' | 'Null' | 'Array' | 'RegExp' | 'Function' | 'Undefined'; - - /** - * Takes a function fn, which takes a single array argument, and returns a function which: - * - takes any number of positional arguments; - * - passes these arguments to fn as an array; and - * - returns the result. - * In other words, R.unapply derives a variadic function from a function which takes an array. - * R.unapply is the inverse of R.apply. - */ - unapply(fn: (args: readonly any[]) => T): (...args: readonly any[]) => T; - - /** - * Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter. - * Any extraneous parameters will not be passed to the supplied function. - */ - unary(fn: (a: T, ...args: readonly any[]) => any): (a: T) => any; - - /** - * Returns a function of arity n from a (manually) curried function. - */ - uncurryN(len: number, fn: (a: any) => any): (...a: readonly any[]) => T; - - /** - * Builds a list from a seed value. Accepts an iterator function, which returns either false - * to stop iteration or an array of length 2 containing the value to add to the resulting - * list and the seed to be used in the next call to the iterator function. - */ - unfold(fn: (seed: T) => [TResult, T] | false, seed: T): TResult[]; - unfold(fn: (seed: T) => [TResult, T] | false): (seed: T) => TResult[]; - - /** - * Combines two lists into a set (i.e. no duplicates) composed of the - * elements of each list. - */ - union(as: readonly T[], bs: readonly T[]): T[]; - union(as: readonly T[]): (bs: readonly T[]) => T[]; - - /** - * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is - * determined according to the value returned by applying the supplied predicate to two list elements. - */ - unionWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; - unionWith(pred: (a: T, b: T) => boolean): F.Curry<(a: readonly T[], b: readonly T[]) => T[]>; - - /** - * Returns a new list containing only one copy of each element in the original list. - */ - uniq(list: readonly T[]): T[]; - - /** - * Returns a new list containing only one copy of each element in the original list, - * based upon the value returned by applying the supplied function to each list element. - * Prefers the first item if the supplied function produces the same value on two items. - * R.equals is used for comparison. - */ - uniqBy(fn: (a: T) => U, list: readonly T[]): T[]; - uniqBy(fn: (a: T) => U): (list: readonly T[]) => T[]; - - /** - * Returns a new list containing only one copy of each element in the original list, based upon the value - * returned by applying the supplied predicate to two list elements. - */ - uniqWith(pred: (x: T, y: T) => boolean, list: readonly T[]): T[]; - uniqWith(pred: (x: T, y: T) => boolean): (list: readonly T[]) => T[]; - - /** - * Tests the final argument by passing it to the given predicate function. If the predicate is not satisfied, - * the function will return the result of calling the whenFalseFn function with the same argument. If the - * predicate is satisfied, the argument is returned as is. - */ - unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U, obj: T): U; - unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U): (obj: T) => U; - - /** - * Returns a new list by pulling every item at the first level of nesting out, and putting - * them in a new array. - */ - unnest(list: T): T.UnNest; - - /** - * Takes a predicate, a transformation function, and an initial value, and returns a value of the same type as - * the initial value. It does so by applying the transformation until the predicate is satisfied, at which point - * it returns the satisfactory value. - */ - until(pred: (val: T) => boolean, fn: (val: T) => U, init: U): U; - until(pred: (val: T) => boolean, fn: (val: T) => U): (init: U) => U; - - /** - * Returns a new copy of the array with the element at the provided index replaced with the given value. - */ - update(index: number, value: T, list: readonly T[]): T[]; - update(index: number, value: T): (list: readonly T[]) => T[]; - - /** - * Accepts a function fn and a list of transformer functions and returns a new curried function. - * When the new function is invoked, it calls the function fn with parameters consisting of the - * result of calling each supplied handler on successive arguments to the new function. - * - * If more arguments are passed to the returned function than transformer functions, those arguments - * are passed directly to fn as additional parameters. If you expect additional arguments that don't - * need to be transformed, although you can ignore them, it's best to pass an identity function so - * that the new function reports the correct arity. - */ - useWith(fn: ((...a: readonly any[]) => any), transformers: Array<((...a: readonly any[]) => any)>): (...a: readonly any[]) => any; - - /** - * Returns a list of all the enumerable own properties of the supplied object. - * Note that the order of the output array is not guaranteed across - * different JS platforms. - */ - values(obj: T): Array; - - /** - * Returns a list of all the properties, including prototype properties, of the supplied - * object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. - */ - valuesIn(obj: any): T[]; - - /** - * Returns a "view" of the given data structure, determined by the given lens. The lens's focus determines which - * portion of the data structure is visible. - */ - view(lens: Lens): (obj: T) => U; - view(lens: Lens, obj: T): U; - - /** - * Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function - * will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, - * the argument is returned as is. - */ - when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U; - when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U; - - /** - * Takes a spec object and a test object and returns true if the test satisfies the spec. - * Any property on the spec that is not a function is interpreted as an equality - * relation. - * - * If the spec has a property mapped to a function, then `where` evaluates the function, passing in - * the test object's value for the property in question, as well as the whole test object. - * - * `where` is well suited to declarativley expressing constraints for other functions, e.g., - * `filter`, `find`, `pickWith`, etc. - */ - where(spec: T, testObj: U): boolean; - where(spec: T): (testObj: U) => boolean; - where(spec: ObjFunc2, testObj: U): boolean; - where(spec: ObjFunc2): (testObj: U) => boolean; - - /** - * Takes a spec object and a test object; returns true if the test satisfies the spec, - * false otherwise. An object satisfies the spec if, for each of the spec's own properties, - * accessing that property of the object gives the same value (in R.eq terms) as accessing - * that property of the spec. - */ - whereEq(spec: T, obj: U): boolean; - whereEq(spec: T): (obj: U) => boolean; - - /** - * Returns a new list without values in the first argument. R.equals is used to determine equality. - * Acts as a transducer if a transformer is given in list position. - */ - without(list1: readonly T[], list2: readonly T[]): T[]; - without(list1: readonly T[]): (list2: readonly T[]) => T[]; - - /** - * Creates a new list out of the two supplied by creating each possible pair from the lists. - */ - xprod(as: readonly K[], bs: readonly V[]): Array>; - xprod(as: readonly K[]): (bs: readonly V[]) => Array>; - - /** - * Creates a new list out of the two supplied by pairing up equally-positioned items from - * both lists. Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`. - */ - zip(list1: readonly K[], list2: readonly V[]): Array>; - zip(list1: readonly K[]): (list2: readonly V[]) => Array>; - - /** - * Creates a new object out of a list of keys and a list of values. - */ - // TODO: Dictionary as a return value is to specific, any seems to loose - zipObj(keys: readonly string[], values: readonly T[]): { [index: string]: T }; - zipObj(keys: readonly string[]): (values: readonly T[]) => { [index: string]: T }; - zipObj(keys: readonly number[], values: readonly T[]): { [index: number]: T }; - zipObj(keys: readonly number[]): (values: readonly T[]) => { [index: number]: T }; - - /** - * Creates a new list out of the two supplied by applying the function to each - * equally-positioned pair in the lists. - */ - zipWith(fn: (x: T, y: U) => TResult, list1: readonly T[], list2: readonly U[]): TResult[]; - zipWith(fn: (x: T, y: U) => TResult, list1: readonly T[]): (list2: readonly U[]) => TResult[]; - zipWith(fn: (x: T, y: U) => TResult): (list1: readonly T[], list2: readonly U[]) => TResult[]; - } -} - -export = R; -export as namespace R; +): { + [key: string]: TResult +}; +export function mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult, obj: any): { [index: string]: TResult }; +export function mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult): (obj: any) => { [index: string]: TResult }; + +/** + * Tests a regular expression agains a String + */ +export function match(regexp: RegExp, str: string): string[]; +export function match(regexp: RegExp): (str: string) => string[]; + +/** + * 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. mathMod requires Integer arguments, and returns NaN + * when the modulus is zero or negative. + */ +export function mathMod(__: Placeholder, b: number): (a: number) => number; +export function mathMod(__: Placeholder): (b: number, a: number) => number; +export function mathMod(a: number, b: number): number; +export function mathMod(a: number): (b: number) => number; + +/** + * Returns the larger of its two arguments. + */ +export function max(a: T, b: T): T; +export function max(a: T): (b: T) => T; + +/** + * Takes a function and two values, and returns whichever value produces + * the larger result when passed to the provided function. + */ +export function maxBy(keyFn: (a: T) => Ord, a: T, b: T): T; +export function maxBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; +export function maxBy(keyFn: (a: T) => Ord): _.F.Curry<(a: T, b: T) => T>; + +/** + * Returns the mean of the given list of numbers. + */ +export function mean(list: readonly number[]): number; + +/** + * Returns the median of the given list of numbers. + */ +export function median(list: readonly number[]): number; + +/** + * Creates a new function that, when invoked, caches the result of calling fn for a given argument set and returns the result. + * Subsequent calls to the memoized fn with the same argument set will not result in an additional call to fn; instead, the cached result for that set of arguments will be returned. + */ +export function memoizeWith any>(keyFn: (...v: Parameters) => string, fn: T): T; + +/** + * Create a new object with the own properties of a + * merged with the own properties of object b. + * This function will *not* mutate passed-in objects. + * + * @deprecated since 0.26 in favor of mergeRight + */ +export function merge(__: Placeholder, b: O2): (a: O1) => Merge; +export function merge(__: Placeholder): (b: O2, a: O1) => Merge; +export function merge(a: O1, b: O2): Merge; +export function merge(a: O1): (b: O2) => Merge; + +/** + * Merges a list of objects together into one object. + */ +export function mergeAll(list: Os): MergeAll; +/** + * 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: + * and both values are objects, the two values will be recursively merged + * otherwise the value from the first object will be used. + */ +export function mergeDeepLeft(o1: O1, o2: O2): Merge; +export function mergeDeepLeft(o1: O1): (o2: O2) => Merge; + +/** + * 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: + * and both values are objects, the two values will be recursively merged + * otherwise the value from the second object will be used. + */ +export function mergeDeepRight(o1: O1, o2: O2): Merge; +export function mergeDeepRight(a: O1): (o2: O2) => Merge; + +/** + * Creates a new object with the own properties of the two provided objects. If a key exists in both objects: + * and both associated values are also objects then the values will be recursively merged. + * otherwise the provided function is applied to associated values using the resulting value as the new value + * associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object. + */ +export function mergeDeepWith(fn: (x: any, z: any) => any, a: T1, b: T2): any; +export function mergeDeepWith(fn: (x: any, z: any) => any, a: T1): (b: T2) => any; +export function mergeDeepWith(fn: (x: any, z: any) => any): (a: T1, b: T2) => any; + +/** + * Creates a new object with the own properties of the two provided objects. If a key exists in both objects: + * and both associated values are also objects then the values will be recursively merged. + * otherwise the provided function is applied to the key and associated values using the resulting value as + * the new value associated with the key. If a key only exists in one object, the value will be associated with + * the key of the resulting object. + */ +export function mergeDeepWithKey(fn: (k: string, x: any, z: any) => any, a: T1, b: T2): any; +export function mergeDeepWithKey(fn: (k: string, x: any, z: any) => any, a: T1): (b: T2) => any; +export function mergeDeepWithKey(fn: (k: string, x: any, z: any) => any): (a: T1, b: T2) => any; + +/** + * Create 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, the value from the first object will be used. + */ +export function mergeLeft(a: O1, b: O2): Merge; +export function mergeLeft(a: O1): (b: O2) => Merge; + +/** + * Create 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, the value from the second object will be used. + */ +export function mergeRight(a: O1, b: O2): Merge; +export function mergeRight(a: O1): (b: O2) => Merge; + +/** + * Creates a new object with the own properties of the two provided objects. If a key exists in both objects, + * the provided function is applied to the values associated with the key in each object, with the result being used as + * the value associated with the key in the returned object. The key will be excluded from the returned object if the + * resulting value is undefined. + */ +export function mergeWith(fn: (x: any, z: any) => any, a: U, b: V): any; +export function mergeWith(fn: (x: any, z: any) => any, a: U): (b: V) => any; +export function mergeWith(fn: (x: any, z: any) => any): (a: U, b: V) => any; + +/** + * Creates a new object with the own properties of the two provided objects. If a key exists in both objects, + * the provided function is applied to the key and the values associated with the key in each object, with the + * result being used as the value associated with the key in the returned object. The key will be excluded from + * the returned object if the resulting value is undefined. + */ +export function mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U, b: V): any; +export function mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U): (b: V) => any; +export function mergeWithKey(fn: (str: string, x: any, z: any) => any): (a: U, b: V) => any; + +/** + * Returns the smaller of its two arguments. + */ +export function min(a: T, b: T): T; +export function min(a: T): (b: T) => T; + +/** + * Takes a function and two values, and returns whichever value produces + * the smaller result when passed to the provided function. + */ +export function minBy(keyFn: (a: T) => Ord, a: T, b: T): T; +export function minBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; +export function minBy(keyFn: (a: T) => Ord): _.F.Curry<(a: T, b: T) => T>; + +/** + * Divides the second parameter by the first and returns the remainder. + * The flipped version (`moduloBy`) may be more useful curried. + * Note that this functions preserves the JavaScript-style behavior for + * modulo. For mathematical modulo see `mathMod` + */ +export function modulo(__: Placeholder, b: number): (a: number) => number; +export function modulo(__: Placeholder): (b: number, a: number) => number; +export function modulo(a: number, b: number): number; +export function modulo(a: number): (b: number) => number; + +/** + * Multiplies two numbers. Equivalent to a * b but curried. + */ +export function multiply(a: number, b: number): number; +export function multiply(a: number): (b: number) => number; + +/** + * Moves an item, at index `from`, to index `to`, in a `list` of elements. + * A new list will be created containing the new elements order. + */ +export function move(from: number, to: number, list: readonly T[]): T[]; +export function move(from: number, to: number): (list: readonly T[]) => T[]; +export function move(from: number): { + (to: number, list: readonly T[]): T[]; + (to: number): (list: readonly T[]) => T[]; +}; + +/** + * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. + * Any extraneous parameters will not be passed to the supplied function. + */ +export function nAry(n: number, fn: (...arg: readonly any[]) => any): (...a: readonly any[]) => any; +export function nAry(n: number): (fn: (...arg: readonly any[]) => any) => (...a: readonly any[]) => any; + +/** + * Negates its argument. + */ +export function negate(n: number): number; + +/** + * Returns true if no elements of the list match the predicate, false otherwise. + */ +export function none(fn: (a: T) => boolean, list: readonly T[]): boolean; +export function none(fn: (a: T) => boolean): (list: readonly T[]) => boolean; + +/** + * A function wrapping a call to the given function in a `!` operation. It will return `true` when the + * underlying function would return a false-y value, and `false` when it would return a truth-y one. + */ +export function not(value: any): boolean; + +/** + * Returns the nth element in a list. + */ +export function nth(n: number, list: readonly T[]): T | undefined; +export function nth(n: number): (list: readonly T[]) => T | undefined; + +/** + * Returns a function which returns its nth argument. + */ +export function nthArg(n: number): (...a: readonly any[]) => any; + +/** + * o is a curried composition function that returns a unary function. Like compose, o performs right-to-left function composition. + * Unlike compose, the rightmost function passed to o will be invoked with only one argument. + * Also, unlike compose, o is limited to accepting only 2 unary functions. + * The name o was chosen because of its similarity to the mathematical composition operator ∘. + */ +export function o(f: (x: T2) => R, g: (x: T1) => T2, v: T1): R; +export function o(f: (x: T2) => R, g: (x: T1) => T2): (v: T1) => R; +export function o( + f: (x: T2) => R, +): { + (g: (x: T1) => T2, v: T1): R; + (g: (x: T1) => T2): (v: T1) => R; +}; + +/** + * Creates an object containing a single key:value pair. + */ +export function objOf(key: K, value: T): Record; +export function objOf(key: K): (value: T) => Record; + +/** + * Returns a singleton array containing the value provided. + */ +export function of(x: T): T[]; + +/** + * Returns a partial copy of an object omitting the keys specified. + */ +export function omit(names: readonly K[], obj: T): Omit; +export function omit(names: readonly K[]): (obj: T) => Omit; + +/** + * Accepts a function fn and returns a function that guards invocation of fn such that fn can only ever be + * called once, no matter how many times the returned function is invoked. The first value calculated is + * returned in subsequent invocations. + */ +export function once(fn: (...a: readonly any[]) => any): (...a: readonly any[]) => any; +export function once(fn: (...a: readonly any[]) => T): (...a: readonly any[]) => T; + +/** + * A function that returns the first truthy of two arguments otherwise the last argument. Note that this is + * NOT short-circuited, meaning that if expressions are passed they are both evaluated. + * Dispatches to the or method of the first argument if applicable. + */ +export function or(a: T, b: U): T | U; +export function or(a: T): (b: U) => T | U; +export function or any); }, U>(fn1: T, val2: U): T | U; +export function or any); }>(fn1: T): (val2: U) => T | U; + +/** + * Returns the result of applying the onFailure function to the value inside a failed promise. + * This is useful for handling rejected promises inside function compositions. + */ +export function otherwise(onError: (error: any) => B | Promise, promise: Promise): Promise; +export function otherwise(onError: (error: any) => B | Promise): (promise: Promise) => Promise; + +/** + * Returns the result of "setting" the portion of the given data structure + * focused by the given lens to the given value. + */ +export function over(lens: Lens, fn: Arity1Fn, value: T): T; +export function over(lens: Lens, fn: Arity1Fn, value: readonly T[]): T[]; +export function over(lens: Lens, fn: Arity1Fn): (value: T) => T; +export function over(lens: Lens, fn: Arity1Fn): (value: readonly T[]) => T[]; +export function over(lens: Lens): (fn: Arity1Fn, value: T) => T; +export function over(lens: Lens): (fn: Arity1Fn, value: readonly T[]) => T[]; + +/** + * Takes two arguments, fst and snd, and returns [fst, snd]. + */ +export function pair(fst: F, snd: S): [F, S]; + +/** + * Takes a function `f` and a list of arguments, and returns a function `g`. + * When applied, `g` returns the result of applying `f` to the arguments + * provided initially followed by the arguments provided to `g`. + */ +export function partial(fn: (x0: V0, x1: V1) => T, args: [V0]): (x1: V1) => T; + +export function partial(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0, V1]): (x2: V2) => T; +export function partial(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V0]): (x1: V1, x2: V2) => T; + +export function partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1, V2]): (x2: V3) => T; +export function partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0, V1]): (x2: V2, x3: V3) => T; +export function partial(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V0]): (x1: V1, x2: V2, x3: V3) => T; + +export function partial(fn: (...a: readonly any[]) => T, args: readonly any[]): (...a: readonly any[]) => T; + +/** + * Takes a function `f` and a list of arguments, and returns a function `g`. + * When applied, `g` returns the result of applying `f` to the arguments + * provided to `g` followed by the arguments provided initially. + */ +export function partialRight(fn: (x0: V0, x1: V1) => T, args: [V1]): (x1: V0) => T; + +export function partialRight(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V1, V2]): (x2: V0) => T; +export function partialRight(fn: (x0: V0, x1: V1, x2: V2) => T, args: [V2]): (x1: V0, x2: V1) => T; + +export function partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V1, V2, V3]): (x0: V0) => T; +export function partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V2, V3]): (x0: V0, x1: V1) => T; +export function partialRight(fn: (x0: V0, x1: V1, x2: V2, x3: V3) => T, args: [V3]): (x0: V0, x1: V1, x2: V2) => T; + +export function partialRight(fn: (...a: readonly any[]) => T, args: readonly any[]): (...a: readonly any[]) => T; + +/** + * Takes a predicate and a list and returns the pair of lists of elements + * which do and do not satisfy the predicate, respectively. + */ +export function partition(fn: (a: string) => boolean, list: readonly string[]): [string[], string[]]; +export function partition(fn: (a: T) => boolean, list: readonly T[]): [T[], T[]]; +export function partition(fn: (a: T) => boolean): (list: readonly T[]) => [T[], T[]]; +export function partition(fn: (a: string) => boolean): (list: readonly string[]) => [string[], string[]]; + +/** + * Retrieve the value at a given path. + */ +export function path(path: Path, obj: any): T | undefined; +export function path(path: Path): (obj: any) => T | undefined; + +/** + * Determines whether a nested path on an object has a specific value, + * in `R.equals` terms. Most likely used to filter a list. + */ +export function pathEq(path: Path, val: any, obj: any): boolean; +export function pathEq(path: Path, val: any): (obj: any) => boolean; +export function pathEq(path: Path): _.F.Curry<(a: any, b: any) => boolean>; + +/** + * If the given, non-null object has a value at the given path, returns the value at that path. + * Otherwise returns the provided default value. + */ +export function pathOr(defaultValue: T, path: Path, obj: any): T; +export function pathOr(defaultValue: T, path: Path): (obj: any) => T; +export function pathOr(defaultValue: T): _.F.Curry<(a: Path, b: any) => T>; + +/** + * Returns true if the specified object property at given path satisfies the given predicate; false otherwise. + */ +export function pathSatisfies(pred: (val: T) => boolean, path: Path, obj: U): boolean; +export function pathSatisfies(pred: (val: T) => boolean, path: Path): (obj: U) => boolean; +export function pathSatisfies(pred: (val: T) => boolean): _.F.Curry<(a: Path, b: U) => boolean>; + +/** + * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the + * property is ignored. + */ +export function pick(names: readonly K[], obj: T): Pick>>; +export function pick(names: readonly K[]): (obj: T) => Pick>>; + +/** + * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist. + */ +export function pickAll(names: readonly string[], obj: T): U; +export function pickAll(names: readonly string[]): (obj: T) => U; + +/** + * Returns a partial copy of an object containing only the keys that satisfy the supplied predicate. + */ +export function pickBy(pred: ObjPred, obj: T): U; +export function pickBy(pred: ObjPred): (obj: T) => U; + +/** + * Creates a new function that runs each of the functions supplied as parameters in turn, + * passing the return value of each function invocation to the next function invocation, + * beginning with whatever arguments were passed to the initial invocation. + */ +// tslint:disable:max-line-length +export function pipe(fn0: () => T1): () => T1; +export function pipe(fn0: (x0: V0) => T1): (x0: V0) => T1; +export function pipe(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2): () => T2; +export function pipe(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1) => T2; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1, x2: V2) => T2; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): () => T3; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x: V0) => T3; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x0: V0, x1: V1) => T3; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (x0: V0, x1: V1, x2: V2) => T3; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): () => T4; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x: V0) => T4; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x0: V0, x1: V1) => T4; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (x0: V0, x1: V1, x2: V2) => T4; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): () => T5; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x: V0) => T5; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x0: V0, x1: V1) => T5; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (x0: V0, x1: V1, x2: V2) => T5; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): () => T6; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x: V0) => T6; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x0: V0, x1: V1) => T6; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x0: V0, x1: V1, x2: V2) => T6; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn: (x: T6) => T7): () => T7; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn: (x: T6) => T7): (x: V0) => T7; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7): (x0: V0, x1: V1) => T7; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7): (x0: V0, x1: V1, x2: V2) => T7; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn: (x: T7) => T8): () => T8; +export function pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn: (x: T7) => T8): (x: V0) => T8; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8): (x0: V0, x1: V1) => T8; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8): (x0: V0, x1: V1, x2: V2) => T8; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9): () => T9; +export function pipe(fn0: (x0: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9): (x0: V0) => T9; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9): (x0: V0, x1: V1) => T9; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9): (x0: V0, x1: V1, x2: V2) => T9; + +export function pipe(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9, fn9: (x: T9) => T10): () => T10; +export function pipe(fn0: (x0: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9, fn9: (x: T9) => T10): (x0: V0) => T10; +export function pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9, fn9: (x: T9) => T10): (x0: V0, x1: V1) => T10; +export function pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9, fn9: (x: T9) => T10): (x0: V0, x1: V1, x2: V2) => T10; +// tslint:enable:max-line-length + +/** + * Returns the left-to-right Kleisli composition of the provided functions, each of which must return a value of a type supported by chain. + * The typings currently support arrays only as return values. + * All functions need to be unary. + * R.pipeK(f, g, h) is equivalent to R.pipe(f, R.chain(g), R.chain(h)). + * + * @deprecated since 0.26 in favor of pipeWith(chain) + */ +// tslint:disable:max-line-length +export function pipeK(fn0: (x0: V0) => T1[]): (x0: V0) => T1[]; +export function pipeK(fn0: (x0: V0) => T1[], fn1: (x: T1) => T2[]): (x0: V0) => T2[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[]): (x: V0) => T3[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[]): (x: V0) => T4[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[]): (x: V0) => T5[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[], fn5: (x: T5) => T6[]): (x: V0) => T6[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[], fn5: (x: T5) => T6[], fn: (x: T6) => T7[]): (x: V0) => T7[]; +export function pipeK(fn0: (x: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[], fn5: (x: T5) => T6[], fn6: (x: T6) => T7[], fn: (x: T7) => T8[]): (x: V0) => T8[]; +export function pipeK(fn0: (x0: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[], fn5: (x: T5) => T6[], fn6: (x: T6) => T7[], fn7: (x: T7) => T8[], fn8: (x: T8) => T9[]): (x0: V0) => T9[]; +export function pipeK(fn0: (x0: V0) => T1[], fn1: (x: T1) => T2[], fn2: (x: T2) => T3[], fn3: (x: T3) => T4[], fn4: (x: T4) => T5[], fn5: (x: T5) => T6[], fn6: (x: T6) => T7[], fn7: (x: T7) => T8[], fn8: (x: T8) => T9[], fn9: (x: T9) => T10[]): (x0: V0) => T10[]; +// tslint:enable:max-line-length + +/** + * Performs left-to-right composition of one or more Promise-returning functions. + * All functions need to be unary. + * + * @deprecated since 0.26 in favor of pipeWith(then) + */ +// tslint:disable:max-line-length +export function pipeP(fn0: (x0: V0) => Promise): (x0: V0) => Promise; +export function pipeP(fn0: (x0: V0) => Promise, fn1: (x: T1) => Promise): (x0: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise, fn5: (x: T5) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise, fn5: (x: T5) => Promise, fn: (x: T6) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise, fn5: (x: T5) => Promise, fn6: (x: T6) => Promise, fn: (x: T7) => Promise): (x: V0) => Promise; +export function pipeP(fn0: (x0: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise, fn5: (x: T5) => Promise, fn6: (x: T6) => Promise, fn7: (x: T7) => Promise, fn8: (x: T8) => Promise): (x0: V0) => Promise; +export function pipeP(fn0: (x0: V0) => Promise, fn1: (x: T1) => Promise, fn2: (x: T2) => Promise, fn3: (x: T3) => Promise, fn4: (x: T4) => Promise, fn5: (x: T5) => Promise, fn6: (x: T6) => Promise, fn7: (x: T7) => Promise, fn8: (x: T8) => Promise, fn9: (x: T9) => Promise): (x0: V0) => Promise; +// tslint:enable:max-line-length + +/* + * Performs left-to-right function composition using transforming function. + * With the current typings, all functions must be unary. + */ +export function pipeWith(composer: (a: any) => any, fns: PipeWithFns): (x0: V0) => T; +export function pipeWith(composer: (a: any) => any): (fns: PipeWithFns) => (x0: V0) => T; + +/** + * Returns a new list by plucking the same named property off all objects in the list supplied. + */ +export function pluck(p: K, list: readonly T[]): Array; +export function pluck(p: number, list: Array<{ [k: number]: T }>): T[]; +export function pluck

(p: P): (list: Array>) => T[]; +export function pluck(p: number): (list: Array<{ [k: number]: T }>) => T[]; + +/** + * Returns a new list with the given element at the front, followed by the contents of the + * list. + */ +export function prepend(el: T, list: readonly T[]): T[]; +export function prepend(el: T): (list: readonly T[]) => T[]; + +/** + * Multiplies together all the elements of a list. + */ +export function product(list: readonly number[]): number; + +/** + * Reasonable analog to SQL `select` statement. + */ +export function project(props: readonly string[], objs: readonly T[]): U[]; +export function project(props: readonly string[]): (objs: readonly T[]) => U[]; + +/** + * Returns a function that when supplied an object returns the indicated property of that object, if it exists. + */ +export function prop(__: Placeholder, obj: T):

(p: P) => T[P]; +export function prop

(p: P, obj: T): T[P]; +export function prop

(p: P): (obj: Record) => T; +export function prop

(p: P): (obj: Record) => T; + +/** + * Determines whether the given property of an object has a specific + * value according to strict equality (`===`). Most likely used to + * filter a list. + */ +export function propEq(name: string | number, val: T, obj: any): boolean; +export function propEq(name: string | number, val: T): (obj: any) => boolean; +export function propEq(name: string | number): { + (val: T, obj: any): boolean; + (val: T): (obj: any) => boolean; +}; + +/** + * Returns true if the specified object property is of the given type; false otherwise. + */ +export function propIs(type: any, name: string, obj: any): boolean; +export function propIs(type: any, name: string): (obj: any) => boolean; +export function propIs(type: any): { + (name: string, obj: any): boolean; + (name: string): (obj: any) => boolean; +}; + +/** + * If the given, non-null object has an own property with the specified name, returns the value of that property. + * Otherwise returns the provided default value. + */ +export function propOr(val: T, __: Placeholder, obj: U): (p: string) => V; +export function propOr(__: Placeholder, p: string, obj: U): (val: T) => V; +export function propOr(val: T, p: string, obj: U): V; +export function propOr(val: T, p: string): (obj: U) => V; +export function propOr(val: T): (p: string, obj: U) => V; + +/** + * Returns the value at the specified property. + * The only difference from `prop` is the parameter order. + * Note: TS1.9 # replace any by dictionary + */ +export function props

(ps: readonly P[], obj: Record): T[]; +export function props

(ps: readonly P[]): (obj: Record) => T[]; +export function props

(ps: readonly P[]): (obj: Record) => T[]; + +/** + * Returns true if the specified object property satisfies the given predicate; false otherwise. + */ +export function propSatisfies(pred: (val: T) => boolean, name: string, obj: U): boolean; +export function propSatisfies(pred: (val: T) => boolean, name: string): (obj: U) => boolean; +export function propSatisfies(pred: (val: T) => boolean): _.F.Curry<(a: string, b: U) => boolean>; + +/** + * Returns a list of numbers from `from` (inclusive) to `to` + * (exclusive). In mathematical terms, `range(a, b)` is equivalent to + * the half-open interval `[a, b)`. + */ +export function range(from: number, to: number): number[]; +export function range(from: number): (to: number) => number[]; + +/** + * Returns a single item by iterating through the list, successively calling the iterator + * function and passing it an accumulator value and the current value from the array, and + * then passing the result to the next call. + */ +export function reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult, list: readonly T[]): TResult; +export function reduce(fn: (acc: TResult, elem: T) => TResult | Reduced): (acc: TResult, list: readonly T[]) => TResult; +export function reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult): (list: readonly T[]) => TResult; + +/** + * Groups the elements of the list according to the result of calling the String-returning function keyFn on each + * element and reduces the elements of each group to a single value via the reducer function valueFn. + */ +export function reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string, list: readonly T[]): { [index: string]: TResult }; +export function reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string): (list: readonly T[]) => { [index: string]: TResult }; +export function reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult): _.F.Curry<(a: (elem: T) => string, b: readonly T[]) => { [index: string]: TResult }>; +export function reduceBy(valueFn: (acc: TResult, elem: T) => TResult): _.F.Curry<(a: TResult, b: (elem: T) => string, c: readonly T[]) => { [index: string]: TResult }>; + +/** + * Returns a value wrapped to indicate that it is the final value of the reduce and + * transduce functions. The returned value should be considered a black box: the internal + * structure is not guaranteed to be stable. + */ +export function reduced(elem: T): Reduced; + +/** + * Returns a single item by iterating through the list, successively calling the iterator + * function and passing it an accumulator value and the current value from the array, and + * then passing the result to the next call. + */ +export function reduceRight(fn: (elem: T, acc: TResult) => TResult, acc: TResult, list: readonly T[]): TResult; +export function reduceRight(fn: (elem: T, acc: TResult) => TResult): (acc: TResult, list: readonly T[]) => TResult; +export function reduceRight(fn: (elem: T, acc: TResult) => TResult, acc: TResult): (list: readonly T[]) => TResult; + +/** + * Like reduce, reduceWhile returns a single item by iterating through the list, successively + * calling the iterator function. reduceWhile also takes a predicate that is evaluated before + * each step. If the predicate returns false, it "short-circuits" the iteration and returns + * the current value of the accumulator. + */ +export function reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult, acc: TResult, list: readonly T[]): TResult; +export function reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult, acc: TResult): (list: readonly T[]) => TResult; +export function reduceWhile(predicate: (acc: TResult, elem: T) => boolean, fn: (acc: TResult, elem: T) => TResult): _.F.Curry<(a: TResult, b: readonly T[]) => TResult>; +export function reduceWhile(predicate: (acc: TResult, elem: T) => boolean): _.F.Curry<(a: (acc: TResult, elem: T) => TResult, b: TResult, c: readonly T[]) => TResult>; + +/** + * Similar to `filter`, except that it keeps only values for which the given predicate + * function returns falsy. + */ +export const reject: Filter; + +/** + * Removes the sub-list of `list` starting at index `start` and containing `count` elements. + */ +export function remove(start: number, count: number, list: readonly T[]): T[]; +export function remove(start: number): (count: number, list: readonly T[]) => T[]; +export function remove(start: number, count: number): (list: readonly T[]) => T[]; + +/** + * Returns a fixed list of size n containing a specified identical value. + */ +export function repeat(a: T, n: number): T[]; +export function repeat(a: T): (n: number) => T[]; + +/** + * Replace a substring or regex match in a string with a replacement. + */ +export function replace(pattern: RegExp | string, replacement: string | ((match: string, ...args: readonly any[]) => string), str: string): string; +export function replace(pattern: RegExp | string, replacement: string | ((match: string, ...args: readonly any[]) => string)): (str: string) => string; +export function replace(pattern: RegExp | string): (replacement: string | ((match: string, ...args: readonly any[]) => string)) => (str: string) => string; + +/** + * Returns a new list with the same elements as the original list, just in the reverse order. + */ +export function reverse(list: readonly T[]): T[]; +/** + * Returns a new string with the characters in reverse order. + */ +export function reverse(str: string): string; + +/** + * Scan is similar to reduce, but returns a list of successively reduced values from the left. + */ +export function scan(fn: (acc: TResult, elem: T) => any, acc: TResult, list: readonly T[]): TResult[]; +export function scan(fn: (acc: TResult, elem: T) => any, acc: TResult): (list: readonly T[]) => TResult[]; +export function scan(fn: (acc: TResult, elem: T) => any): (acc: TResult, list: readonly T[]) => TResult[]; + +/** + * Returns the result of "setting" the portion of the given data structure focused by the given lens to the + * given value. + */ +export function set(lens: Lens, a: U, obj: T): T; +export function set(lens: Lens, a: U): (obj: T) => T; +export function set(lens: Lens): (a: U, obj: T) => T; + +/** + * Returns the elements from `xs` starting at `a` and ending at `b - 1`. + */ +export function slice(a: number, b: number, list: string): string; +export function slice(a: number, b: number, list: readonly T[]): T[]; +export function slice(a: number, b: number): { + (list: string): string; + (list: readonly T[]): T[]; +}; +export function slice(a: number): { + (b: number, list: string): string; + (b: number, list: readonly T[]): T[]; +}; + +/** + * Returns a copy of the list, sorted according to the comparator function, which should accept two values at a + * time and return a negative number if the first value is smaller, a positive number if it's larger, and zero + * if they are equal. + */ +export function sort(fn: (a: T, b: T) => number, list: readonly T[]): T[]; +export function sort(fn: (a: T, b: T) => number): (list: readonly T[]) => T[]; + +/** + * Sorts the list according to a key generated by the supplied function. + */ +export function sortBy(fn: (a: T) => Ord, list: readonly T[]): T[]; +export function sortBy(fn: (a: any) => Ord): (list: readonly T[]) => T[]; + +/** + * Sorts a list according to a list of comparators. + */ +export function sortWith(fns: Array<((a: T, b: T) => number)>, list: readonly T[]): T[]; +export function sortWith(fns: Array<((a: T, b: T) => number)>): (list: readonly T[]) => T[]; + +/** + * Splits a string into an array of strings based on the given + * separator. + */ +export function split(sep: string | RegExp): (str: string) => string[]; +export function split(sep: string | RegExp, str: string): string[]; + +/** + * Splits a given list or string at a given index. + */ +export function splitAt(index: number, list: readonly T[]): [T[], T[]]; +export function splitAt(index: number, list: string): [string, string]; +export function splitAt(index: number): { + (list: readonly T[]): [T[], T[]]; + (list: string): [string, string]; +}; + +/** + * Splits a collection into slices of the specified length. + */ +export function splitEvery(a: number, list: readonly T[]): T[][]; +export function splitEvery(a: number, list: string): string[]; +export function splitEvery(a: number): { + (list: string): string[]; + (list: readonly T[]): T[][]; +}; + +/** + * Takes a list and a predicate and returns a pair of lists with the following properties: + * - the result of concatenating the two output lists is equivalent to the input list; + * - none of the elements of the first output list satisfies the predicate; and + * - if the second output list is non-empty, its first element satisfies the predicate. + */ +export function splitWhen(pred: (val: T) => boolean, list: readonly U[]): U[][]; +export function splitWhen(pred: (val: T) => boolean): (list: readonly U[]) => U[][]; + +/** + * Checks if a list starts with the provided values + */ +export function startsWith(a: string, list: string): boolean; +export function startsWith(a: string): (list: string) => boolean; +export function startsWith(a: T | readonly T[], list: readonly T[]): boolean; +export function startsWith(a: T | readonly T[]): (list: readonly T[]) => boolean; + +/** + * Subtracts two numbers. Equivalent to `a - b` but curried. + */ +export function subtract(__: Placeholder, b: number): (a: number) => number; +export function subtract(__: Placeholder): (b: number, a: number) => number; +export function subtract(a: number, b: number): number; +export function subtract(a: number): (b: number) => number; + +/** + * Adds together all the elements of a list. + */ +export function sum(list: readonly number[]): number; + +/** + * Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. + */ +export function symmetricDifference(list1: readonly T[], list2: readonly T[]): T[]; +export function symmetricDifference(list: readonly T[]): (list: readonly T[]) => T[]; + +/** + * Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. + * Duplication is determined according to the value returned by applying the supplied predicate to two list elements. + */ +export function symmetricDifferenceWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; +export function symmetricDifferenceWith(pred: (a: T, b: T) => boolean): _.F.Curry<(a: readonly T[], b: readonly T[]) => T[]>; + +/** + * A function that always returns true. Any passed in parameters are ignored. + */ +export function T(): boolean; + +/** + * Returns all but the first element of a list or string. + */ +export function tail(list: string): string; +export function tail(list: readonly T[]): T[]; + +/** + * Returns a new list containing the first `n` elements of the given list. If + * `n > * list.length`, returns a list of `list.length` elements. + */ +export function take(n: number, xs: readonly T[]): T[]; +export function take(n: number, xs: string): string; +export function take(n: number): { + (xs: string): string; + (xs: readonly T[]): T[]; +}; + +/** + * Returns a new list containing the last n elements of the given list. If n > list.length, + * returns a list of list.length elements. + */ +export function takeLast(n: number, xs: readonly T[]): T[]; +export function takeLast(n: number, xs: string): string; +export function takeLast(n: number): { + (xs: readonly T[]): T[]; + (xs: string): string; +}; + +/** + * Returns a new list containing the last n elements of a given list, passing each value + * to the supplied predicate function, and terminating when the predicate function returns + * false. Excludes the element that caused the predicate function to fail. The predicate + * function is passed one argument: (value). + */ +export function takeLastWhile(pred: (a: T) => boolean, list: readonly T[]): T[]; +export function takeLastWhile(pred: (a: T) => boolean): (list: readonly T[]) => T[]; + +/** + * Returns a new list containing the first `n` elements of a given list, passing each value + * to the supplied predicate function, and terminating when the predicate function returns + * `false`. + */ +export function takeWhile(fn: (x: T) => boolean, list: readonly T[]): T[]; +export function takeWhile(fn: (x: T) => boolean): (list: readonly T[]) => T[]; + +/** + * The function to call with x. The return value of fn will be thrown away. + */ +export function tap(fn: (a: T) => any, value: T): T; +export function tap(fn: (a: T) => any): (value: T) => T; + +/** + * Determines whether a given string matches a given regular expression. + */ +export function test(regexp: RegExp, str: string): boolean; +export function test(regexp: RegExp): (str: string) => boolean; + +/** + * Returns the result of applying the onSuccess function to the value inside a successfully resolved promise. This is useful for working with promises inside function compositions. + */ +export function then(onSuccess: (a: A) => B | Promise, promise: Promise): Promise; +export function then(onSuccess: (a: A) => B | Promise): (promise: Promise) => Promise; + +/** + * Creates a thunk out of a function. + * A thunk delays a calculation until its result is needed, providing lazy evaluation of arguments. + */ +export function thunkify any>(fn: F): _.F.Curry<(...args: Parameters) => (() => ReturnType)>; + +/** + * Calls an input function `n` times, returning an array containing the results of those + * function calls. + */ +export function times(fn: (i: number) => T, n: number): T[]; +export function times(fn: (i: number) => T): (n: number) => T[]; + +/** + * The lower case version of a string. + */ +export function toLower(str: string): string; + +/** + * Converts an object into an array of key, value arrays. + * Only the object's own properties are used. + * Note that the order of the output array is not guaranteed to be + * consistent across different JS platforms. + */ +export function toPairs(obj: { [k: string]: S } | { [k: number]: S }): Array<[string, S]>; + +/** + * Converts an object into an array of key, value arrays. + * The object's own properties and prototype properties are used. + * Note that the order of the output array is not guaranteed to be + * consistent across different JS platforms. + */ +export function toPairsIn(obj: { [k: string]: S } | { [k: number]: S }): Array<[string, S]>; + +/** + * Returns the string representation of the given value. eval'ing the output should + * result in a value equivalent to the input value. Many of the built-in toString + * methods do not satisfy this requirement. + * + * If the given value is an [object Object] with a toString method other than + * Object.prototype.toString, this method is invoked with no arguments to produce the + * return value. This means user-defined constructor functions can provide a suitable + * toString method. + */ +export function toString(val: T): string; + +/** + * The upper case version of a string. + */ +export function toUpper(str: string): string; + +/** + * Initializes a transducer using supplied iterator function. Returns a single item by iterating through the + * list, successively calling the transformed iterator function and passing it an accumulator value and the + * current value from the array, and then passing the result to the next call. + */ +export function transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[], acc: readonly T[], list: readonly T[]): U; +export function transduce(xf: (arg: readonly T[]) => T[]): (fn: (acc: readonly U[], val: U) => U[], acc: readonly T[], list: readonly T[]) => U; +export function transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[]): (acc: readonly T[], list: readonly T[]) => U; +export function transduce(xf: (arg: readonly T[]) => T[], fn: (acc: readonly U[], val: U) => U[], acc: readonly T[]): (list: readonly T[]) => U; + +/** + * Transposes the rows and columns of a 2D list. When passed a list of n lists of length x, returns a list of x lists of length n. + */ +export function transpose(list: readonly T[][]): T[][]; + +/** + * Maps an Applicative-returning function over a Traversable, then uses + * sequence to transform the resulting Traversable of Applicative into + * an Applicative of Traversable. + */ +export function traverse(of: (a: B) => B[], fn: (t: A) => B[], list: readonly A[]): B[][]; +export function traverse(of: (a: B) => B[], fn: (t: A) => B[]): (list: readonly A[]) => B[][]; +export function traverse(of: (a: B) => B[]): (fn: (t: A) => B[], list: readonly A[]) => B[][]; + +/** + * Removes (strips) whitespace from both ends of the string. + */ +export function trim(str: string): string; + +/** + * tryCatch takes two functions, a tryer and a catcher. The returned function evaluates the tryer; if it does + * not throw, it simply returns the result. If the tryer does throw, the returned function evaluates the catcher + * function and returns its result. Note that for effective composition with this function, both the tryer and + * catcher functions must return the same type of results. + */ +export function tryCatch(tryer: (...args: readonly any[]) => T, catcher: (...args: readonly any[]) => T): (...args: readonly any[]) => T; + +/** + * Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', + * 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them + * all as 'Object'. + */ +export function type(val: any): 'Object' | 'Number' | 'Boolean' | 'String' | 'Null' | 'Array' | 'RegExp' | 'Function' | 'Undefined'; + +/** + * Takes a function fn, which takes a single array argument, and returns a function which: + * - takes any number of positional arguments; + * - passes these arguments to fn as an array; and + * - returns the result. + * In other words, R.unapply derives a variadic function from a function which takes an array. + * R.unapply is the inverse of R.apply. + */ +export function unapply(fn: (args: readonly any[]) => T): (...args: readonly any[]) => T; + +/** + * Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter. + * Any extraneous parameters will not be passed to the supplied function. + */ +export function unary(fn: (a: T, ...args: readonly any[]) => any): (a: T) => any; + +/** + * Returns a function of arity n from a (manually) curried function. + */ +export function uncurryN(len: number, fn: (a: any) => any): (...a: readonly any[]) => T; + +/** + * Builds a list from a seed value. Accepts an iterator function, which returns either false + * to stop iteration or an array of length 2 containing the value to add to the resulting + * list and the seed to be used in the next call to the iterator function. + */ +export function unfold(fn: (seed: T) => [TResult, T] | false, seed: T): TResult[]; +export function unfold(fn: (seed: T) => [TResult, T] | false): (seed: T) => TResult[]; + +/** + * Combines two lists into a set (i.e. no duplicates) composed of the + * elements of each list. + */ +export function union(as: readonly T[], bs: readonly T[]): T[]; +export function union(as: readonly T[]): (bs: readonly T[]) => T[]; + +/** + * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is + * determined according to the value returned by applying the supplied predicate to two list elements. + */ +export function unionWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; +export function unionWith(pred: (a: T, b: T) => boolean): _.F.Curry<(a: readonly T[], b: readonly T[]) => T[]>; + +/** + * Returns a new list containing only one copy of each element in the original list. + */ +export function uniq(list: readonly T[]): T[]; + +/** + * Returns a new list containing only one copy of each element in the original list, + * based upon the value returned by applying the supplied function to each list element. + * Prefers the first item if the supplied function produces the same value on two items. + * R.equals is used for comparison. + */ +export function uniqBy(fn: (a: T) => U, list: readonly T[]): T[]; +export function uniqBy(fn: (a: T) => U): (list: readonly T[]) => T[]; + +/** + * Returns a new list containing only one copy of each element in the original list, based upon the value + * returned by applying the supplied predicate to two list elements. + */ +export function uniqWith(pred: (x: T, y: T) => boolean, list: readonly T[]): T[]; +export function uniqWith(pred: (x: T, y: T) => boolean): (list: readonly T[]) => T[]; + +/** + * Tests the final argument by passing it to the given predicate function. If the predicate is not satisfied, + * the function will return the result of calling the whenFalseFn function with the same argument. If the + * predicate is satisfied, the argument is returned as is. + */ +export function unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U, obj: T): U; +export function unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U): (obj: T) => U; + +/** + * Returns a new list by pulling every item at the first level of nesting out, and putting + * them in a new array. + */ +export function unnest(list: T): _.T.UnNest; + +/** + * Takes a predicate, a transformation function, and an initial value, and returns a value of the same type as + * the initial value. It does so by applying the transformation until the predicate is satisfied, at which point + * it returns the satisfactory value. + */ +export function until(pred: (val: T) => boolean, fn: (val: T) => U, init: U): U; +export function until(pred: (val: T) => boolean, fn: (val: T) => U): (init: U) => U; + +/** + * Returns a new copy of the array with the element at the provided index replaced with the given value. + */ +export function update(index: number, value: T, list: readonly T[]): T[]; +export function update(index: number, value: T): (list: readonly T[]) => T[]; + +/** + * Accepts a function fn and a list of transformer functions and returns a new curried function. + * When the new function is invoked, it calls the function fn with parameters consisting of the + * result of calling each supplied handler on successive arguments to the new function. + * + * If more arguments are passed to the returned function than transformer functions, those arguments + * are passed directly to fn as additional parameters. If you expect additional arguments that don't + * need to be transformed, although you can ignore them, it's best to pass an identity function so + * that the new function reports the correct arity. + */ +export function useWith(fn: ((...a: readonly any[]) => any), transformers: Array<((...a: readonly any[]) => any)>): (...a: readonly any[]) => any; + +/** + * Returns a list of all the enumerable own properties of the supplied object. + * Note that the order of the output array is not guaranteed across + * different JS platforms. + */ +export function values(obj: T): Array; + +/** + * Returns a list of all the properties, including prototype properties, of the supplied + * object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms. + */ +export function valuesIn(obj: any): T[]; + +/** + * Returns a "view" of the given data structure, determined by the given lens. The lens's focus determines which + * portion of the data structure is visible. + */ +export function view(lens: Lens): (obj: T) => U; +export function view(lens: Lens, obj: T): U; + +/** + * Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function + * will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, + * the argument is returned as is. + */ +export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U; +export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U; + +/** + * Takes a spec object and a test object and returns true if the test satisfies the spec. + * Any property on the spec that is not a function is interpreted as an equality + * relation. + * + * If the spec has a property mapped to a function, then `where` evaluates the function, passing in + * the test object's value for the property in question, as well as the whole test object. + * + * `where` is well suited to declaratively expressing constraints for other functions, e.g., + * `filter`, `find`, `pickWith`, etc. + */ +export function where(spec: T, testObj: U): boolean; +export function where(spec: T): (testObj: U) => boolean; +export function where(spec: ObjFunc2, testObj: U): boolean; +export function where(spec: ObjFunc2): (testObj: U) => boolean; + +/** + * Takes a spec object and a test object; returns true if the test satisfies the spec, + * false otherwise. An object satisfies the spec if, for each of the spec's own properties, + * accessing that property of the object gives the same value (in R.eq terms) as accessing + * that property of the spec. + */ +export function whereEq(spec: T, obj: U): boolean; +export function whereEq(spec: T): (obj: U) => boolean; + +/** + * Returns a new list without values in the first argument. R.equals is used to determine equality. + * Acts as a transducer if a transformer is given in list position. + */ +export function without(list1: readonly T[], list2: readonly T[]): T[]; +export function without(list1: readonly T[]): (list2: readonly T[]) => T[]; + +/** + * Creates a new list out of the two supplied by creating each possible pair from the lists. + */ +export function xprod(as: readonly K[], bs: readonly V[]): Array>; +export function xprod(as: readonly K[]): (bs: readonly V[]) => Array>; + +/** + * Creates a new list out of the two supplied by pairing up equally-positioned items from + * both lists. Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`. + */ +export function zip(list1: readonly K[], list2: readonly V[]): Array>; +export function zip(list1: readonly K[]): (list2: readonly V[]) => Array>; + +/** + * Creates a new object out of a list of keys and a list of values. + */ +// TODO: Dictionary as a return value is to specific, any seems to loose +export function zipObj(keys: readonly string[], values: readonly T[]): { [index: string]: T }; +export function zipObj(keys: readonly string[]): (values: readonly T[]) => { [index: string]: T }; +export function zipObj(keys: readonly number[], values: readonly T[]): { [index: number]: T }; +export function zipObj(keys: readonly number[]): (values: readonly T[]) => { [index: number]: T }; + +/** + * Creates a new list out of the two supplied by applying the function to each + * equally-positioned pair in the lists. + */ +export function zipWith(fn: (x: T, y: U) => TResult, list1: readonly T[], list2: readonly U[]): TResult[]; +export function zipWith(fn: (x: T, y: U) => TResult, list1: readonly T[]): (list2: readonly U[]) => TResult[]; +export function zipWith(fn: (x: T, y: U) => TResult): (list1: readonly T[], list2: readonly U[]) => TResult[]; + +export as namespace R diff --git a/types/ramda/package.json b/types/ramda/package.json index ea436bd5e5..8715621bd8 100644 --- a/types/ramda/package.json +++ b/types/ramda/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "ts-toolbelt": "^4.10.7" + "ts-toolbelt": "^4.12.0" } } diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 013d4983e1..f1a92a2cd9 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1,4 +1,5 @@ import * as R from "ramda"; +import { Dictionary } from "ramda/tools"; function double(x: number): number { return x + x; @@ -312,7 +313,7 @@ R.times(i, 5); return n % 2 === 0; } const rejectEven = R.reject(isEven); - const objB: R.Dictionary = rejectEven({ a: 0, b: 1 }); // => { b: 1 } + const objB: Dictionary = rejectEven({ a: 0, b: 1 }); // => { b: 1 } const listB: number[] = rejectEven([0, 1]); // => [1] }; @@ -321,7 +322,7 @@ R.times(i, 5); return n % 2 === 0; } - const a: R.Dictionary = R.pipe( + const a: Dictionary = R.pipe( R.filter(isEven), )({ a: 0, b: 1 }); // => { a: 0 } @@ -329,7 +330,7 @@ R.times(i, 5); R.filter(isEven), )([0, 1]); // => [0] - const c: R.Dictionary = R.pipe( + const c: Dictionary = R.pipe( R.reject(isEven), )({ a: 0, b: 1 }); // => { b: 1 } diff --git a/types/ramda/test/filter-tests.ts b/types/ramda/test/filter-tests.ts index fb22a6a46f..cf1b66abeb 100644 --- a/types/ramda/test/filter-tests.ts +++ b/types/ramda/test/filter-tests.ts @@ -1,4 +1,5 @@ import * as R from 'ramda'; +import { Dictionary } from 'ramda/tools'; () => { function isEven(n: number) { @@ -6,17 +7,17 @@ import * as R from 'ramda'; } const filterEven = R.filter(isEven); - const objA: R.Dictionary = filterEven({ a: 0, b: 1 }); // => { a: 0 } + const objA: Dictionary = filterEven({ a: 0, b: 1 }); // => { a: 0 } const listA: number[] = filterEven([0, 1]); // => [0] }; () => { const compact = R.filter(Boolean); - const objA: R.Dictionary = compact({ a: 0, b: 1 }); // => { b: 1 } + const objA: Dictionary = compact({ a: 0, b: 1 }); // => { b: 1 } const listA: number[] = compact([0, 1]); // => [1] const omitEmptyString = R.filter((val: string) => val !== ''); - const objB: R.Dictionary = omitEmptyString({ a: '', b: 'foo' }); // => { b: 'foo' } + const objB: Dictionary = omitEmptyString({ a: '', b: 'foo' }); // => { b: 'foo' } const listB: string[] = omitEmptyString(['', 'foo']); // => ['foo'] const objC = omitEmptyString({ some: 42 }); // $ExpectError diff --git a/types/ramda/test/maxBy-tests.ts b/types/ramda/test/maxBy-tests.ts index 75b4a70118..e530cf7c6c 100644 --- a/types/ramda/test/maxBy-tests.ts +++ b/types/ramda/test/maxBy-tests.ts @@ -1,7 +1,8 @@ import * as R from 'ramda'; +import { Ord } from 'ramda/tools'; () => { - function cmp(obj: { x: R.Ord }) { + function cmp(obj: { x: Ord }) { return obj.x; } diff --git a/types/ramda/test/minBy-tests.ts b/types/ramda/test/minBy-tests.ts index daaa86c5ec..0fea23a4d5 100644 --- a/types/ramda/test/minBy-tests.ts +++ b/types/ramda/test/minBy-tests.ts @@ -1,7 +1,8 @@ import * as R from 'ramda'; +import { Ord } from 'ramda/tools'; () => { - function cmp(obj: { x: R.Ord }) { + function cmp(obj: { x: Ord }) { return obj.x; } diff --git a/types/ramda/tools.d.ts b/types/ramda/tools.d.ts index b15b813e7d..25bb9d8e3c 100644 --- a/types/ramda/tools.d.ts +++ b/types/ramda/tools.d.ts @@ -1,5 +1,435 @@ -/// +import { A, O, T } from "ts-toolbelt"; -declare namespace Tools { - type ValueOfRecord = R extends Record ? T : never; +// /////////////////////////////////////////////////////////////////////////////////////// +// TOOLS ///////////////////////////////////////////////////////////////////////////////// + +// Here lies a loose collection of tools that compute types for the functions in "index.d.ts" +// The goal of this file is to keep "index.d.ts" readable as well as hiding implementations + +// WHEN ADDING A NEW TOOL +// - Add documentation for the tool you've created +// - Add on your tool's docs + +// TODO +// - Types need proper descriptions, so that we know what they do + +// --------------------------------------------------------------------------------------- +// A + +/** + * + */ +export type Arity0Fn = () => any; + +/** + * + */ +export type Arity1Fn = (a: any) => any; + +/** + * + */ +export type Arity2Fn = (a: any, b: any) => any; + +/** + * + */ +export interface ArrayLike { + nodeType: number; } + +/** + * + * @param K + */ +export interface AssocPartialOne { + (val: T): (obj: U) => Record & U; + (val: T, obj: U): Record & U; +} + +// --------------------------------------------------------------------------------------- +// C + +/** + * + */ +export interface CharList extends String { + push(x: string): void; +} + +/** + * + * @param V0 + * @param R + */ +export type ComposeWithFns = [ + (x0: V0) => R +] | [ + (x: any) => R, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +] | [ + (x: any) => R, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: V0) => any +]; + +// --------------------------------------------------------------------------------------- +// D + +/** + * + * @param A + */ +export interface Dictionary { + [index: string]: A; +} + +// --------------------------------------------------------------------------------------- +// E + +/** + * Represents all objects evolvable with Evolver E + * @param E + */ +export type Evolvable = { + [P in keyof E]?: Evolved; +}; + +/** + * + * @param O + * @param E + */ +export type Evolve, E extends Evolver> = { + [P in keyof O]: P extends keyof E + ? EvolveValue + : O[P]; +}; + +/** + * + * @param A + */ +type Evolved = + A extends (value: infer V) => any + ? V + : A extends Evolver + ? Evolvable + : never; + +/** + * + */ +export interface Evolver { + [key: string]: ((value: any) => any) | Evolver; +} + +/** + * + * @param O + * @param E + */ +type EvolveNestedValue = + O extends object + ? O extends Evolvable + ? Evolve + : never + : never; + +/** + * + * @param V + * @param E + */ +type EvolveValue = + E extends (value: V) => any + ? ReturnType + : E extends Evolver + ? EvolveNestedValue + : never; + +// --------------------------------------------------------------------------------------- +// F + +/** + * + */ +export interface Filter { + (fn: (value: T) => boolean): FilterOnceApplied; + (fn: (value: T) => boolean): (list: readonly T[]) => T[]; + (fn: (value: T) => boolean): (list: Dictionary) => Dictionary; + (fn: (value: T) => boolean, list: readonly T[]): T[]; + (fn: (value: T) => boolean, obj: Dictionary): Dictionary; +} + +/** + * + * @param A + */ +type FilterOnceApplied = + >(source: K) => + K extends Array + ? U[] + : K extends Dictionary + ? Dictionary + : never; + +/** + * + * @param A + */ +export interface Functor { + map(fn: (a: A) => U): Functor; +} + +// --------------------------------------------------------------------------------------- +// K + +/** + * + * @param K + * @param V + */ +export type KeyValuePair = [K, V]; + +// --------------------------------------------------------------------------------------- +// L + +/** + * + */ +export interface Lens { + (obj: T): U; + set(str: string, obj: T): U; +} + +// --------------------------------------------------------------------------------------- +// M + +/** + * Merge an object `O1` with `O2` + * @param O1 + * @param O2 + * @param Depth + * + * `O1` & `O2` are intersected with `[]` so that we can + * handle the scenario where we merge arrays (like ramda). + * Ramda removes array props when merging arrays, and thus + * only keeps own properties. This is what `ObjectOf` does. + * + * => ramda's `merge` functions are 100% properly typed. + * + * + */ +export type Merge = + O.MergeUp, T.ObjectOf, Depth>; + +/** + * Merge multiple objects `Os` with each other + * @param Os + * + * It essentially works like [[Merge]], since the utility + * `MergeUp` is used by `AssignUp` internally. + * + * + */ +export type MergeAll = + O.AssignUp<{}, Os> extends infer M + ? {} extends M // nothing merged => bcs no `as const` + ? T.UnionOf // so we output the approximate types + : T.ObjectOf // otherwise, we can get accurate types + : never; + +// --------------------------------------------------------------------------------------- +// O + +/** + * + */ +export type ObjPred = (value: any, key: string) => boolean; + +/** + * + */ +export type Ord = number | string | boolean | Date; + +// --------------------------------------------------------------------------------------- +// P + +/** + * + */ +export type Path = Array<(number | string)>; + +/** + * + */ +export type Placeholder = A.x & {'@@functional/placeholder': true}; + +/** + * + */ +export type Pred = (...a: readonly any[]) => boolean; + +/** + * + * @param V0 + * @param R + */ +export type PipeWithFns = [ + (x0: V0) => R +] | [ + (x0: V0) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +] | [ + (x0: V0) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => any, + (x: any) => R +]; + +// --------------------------------------------------------------------------------------- +// R + +/** + * + * @param A + */ +export interface Reduced { + '@@transducer/value': A; + '@@transducer/reduced': true; +} + +// --------------------------------------------------------------------------------------- +// S + +/** + * + * @param A + */ +export type SafePred = (...a: readonly A[]) => boolean; + +// --------------------------------------------------------------------------------------- +// V + +/** + * + * @param R + */ +export type ValueOfRecord = + R extends Record + ? T + : never; + +export {};

(prop: P): (obj1: Record, obj2: Record) => boolean; +export function eqProps(prop: string, obj1: T): (obj2: U) => boolean; + +/** + * Returns true if its arguments are equivalent, false otherwise. Dispatches to an equals method if present. + * Handles cyclical data structures. + */ +export function equals(a: T, b: T): boolean; +export function equals(a: T): (b: T) => boolean; + +/** + * Creates a new object by evolving a shallow copy of object, according to the transformation functions. + */ +export function evolve>(transformations: E, obj: V): Evolve; +export function evolve(transformations: E): >(obj: V) => Evolve; + +/* +* A function that always returns false. Any passed in parameters are ignored. +*/ +export function F(): boolean; + +/** + * Returns a new list containing only those items that match a given predicate function. The predicate function is passed one argument: (value). + */ +export const filter: Filter; + +/** + * Returns the first element of the list which matches the predicate, or `undefined` if no + * element matches. + */ +export function find(fn: (a: T) => boolean, list: readonly T[]): T | undefined; +export function find(fn: (a: T) => boolean): (list: readonly T[]) => T | undefined; + +/** + * Returns the index of the first element of the list which matches the predicate, or `-1` + * if no element matches. + */ +export function findIndex(fn: (a: T) => boolean, list: readonly T[]): number; +export function findIndex(fn: (a: T) => boolean): (list: readonly T[]) => number; + +/** + * Returns the last element of the list which matches the predicate, or `undefined` if no + * element matches. + */ +export function findLast(fn: (a: T) => boolean, list: readonly T[]): T | undefined; +export function findLast(fn: (a: T) => boolean): (list: readonly T[]) => T | undefined; + +/** + * Returns the index of the last element of the list which matches the predicate, or + * `-1` if no element matches. + */ +export function findLastIndex(fn: (a: T) => boolean, list: readonly T[]): number; +export function findLastIndex(fn: (a: T) => boolean): (list: readonly T[]) => number; + +/** + * Returns a new list by pulling every item out of it (and all its sub-arrays) and putting + * them in a new array, depth-first. + */ +export function flatten(list: T): _.T.Flatten; + +/** + * Returns a new function much like the supplied one, except that the first two arguments' + * order is reversed. + */ +export function flip(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult; +export function flip any, P extends _.F.Parameters>(fn: F): _.F.Curry<(...args: _.T.Merge<[P[1], P[0]], P>) => _.F.Return>; + +/** + * Iterate over an input list, calling a provided function fn for each element in the list. + */ +export function forEach(fn: (x: T) => void, list: readonly T[]): T[]; +export function forEach(fn: (x: T) => void): (list: readonly T[]) => T[]; +export function forEach(fn: (x: T) => void, list: readonly T[]): T[]; +export function forEach(fn: (x: T) => void): (list: readonly T[]) => T[]; + +/** + * Iterate over an input object, calling a provided function fn for each key and value in the object. + */ +export function forEachObjIndexed(fn: (value: T[keyof T], key: keyof T, obj: T) => void, obj: T): T; +export function forEachObjIndexed(fn: (value: T[keyof T], key: keyof T, obj: T) => void): (obj: T) => T; + +/** + * Creates a new object out of a list key-value pairs. + */ +export function fromPairs(pairs: Array>): { [index: string]: V }; +export function fromPairs(pairs: Array>): { [index: number]: V }; + +/** + * Splits a list into sublists stored in an object, based on the result of + * calling a String-returning function + * on each element, and grouping the results according to values returned. + */ +export function groupBy(fn: (a: T) => string, list: readonly T[]): { [index: string]: T[] }; +export function groupBy(fn: (a: T) => string): (list: readonly T[]) => { [index: string]: T[] }; + +/** + * Takes a list and returns a list of lists where each sublist's elements are all "equal" according to the provided equality function + */ +export function groupWith(fn: (x: T, y: T) => boolean): (list: readonly T[]) => T[][]; +export function groupWith(fn: (x: T, y: T) => boolean, list: readonly T[]): T[][]; +export function groupWith(fn: (x: T, y: T) => boolean, list: string): string[]; + +/** + * Returns true if the first parameter is greater than the second. + */ +export function gt(__: Placeholder, b: number): (a: number) => boolean; +export function gt(__: Placeholder): (b: number, a: number) => boolean; +export function gt(a: number, b: number): boolean; +export function gt(a: number): (b: number) => boolean; + +/** + * Returns true if the first parameter is greater than or equal to the second. + */ +export function gte(__: Placeholder, b: number): (a: number) => boolean; +export function gte(__: Placeholder): (b: number, a: number) => boolean; +export function gte(a: number, b: number): boolean; +export function gte(a: number): (b: number) => boolean; + +/** + * Returns whether or not an object has an own property with the specified name. + */ +export function has(__: Placeholder, obj: T): (s: string) => boolean; +export function has(__: Placeholder): (obj: T, s: string) => boolean; +export function has(s: string, obj: T): boolean; +export function has(s: string): (obj: T) => boolean; + +/** + * Returns whether or not an object or its prototype chain has a property with the specified name + */ +export function hasIn(s: string, obj: T): boolean; +export function hasIn(s: string): (obj: T) => boolean; + +/** + * Returns whether or not a path exists in an object. Only the object's own properties are checked. + */ +export function hasPath(list: readonly string[], obj: T): boolean; +export function hasPath(list: readonly string[]): (obj: T) => boolean; + +/** + * Returns the first element in a list. + * In some libraries this function is named `first`. + */ +export function head(str: string): string; +export function head(list: readonly []): undefined; +export function head(list: readonly T[]): T | undefined; + +/** + * Returns true if its arguments are identical, false otherwise. Values are identical if they reference the + * same memory. NaN is identical to NaN; 0 and -0 are not identical. + */ +export function identical(a: T, b: T): boolean; +export function identical(a: T): (b: T) => boolean; + +/** + * A function that does nothing but return the parameter supplied to it. Good as a default + * or placeholder function. + */ +export function identity(a: T): T; + +/** + * Creates a function that will process either the onTrue or the onFalse function depending upon the result + * of the condition predicate. + */ +export function ifElse(fn: Pred, onTrue: Arity1Fn, onFalse: Arity1Fn): Arity1Fn; +export function ifElse(fn: Pred, onTrue: Arity2Fn, onFalse: Arity2Fn): Arity2Fn; + +/** + * Increments its argument. + */ +export function inc(n: number): number; + +/** + * Given a target, this function checks a list for the target and returns a boolean. + * Given a string, this function checks for the string in another string or list and returns + * a boolean. + */ +export function includes(s: string, list: readonly string[] | string): boolean; +export function includes(s: string): (list: readonly string[] | string) => boolean; +export function includes(target: T, list: readonly T[]): boolean; +export function includes(target: T): (list: readonly T[]) => boolean; + +/** + * Given a function that generates a key, turns a list of objects into an object indexing the objects + * by the given key. + */ +export function indexBy(fn: (a: T) => string, list: readonly T[]): { [key: string]: T }; +export function indexBy(fn: (a: T) => string): (list: readonly T[]) => { [key: string]: T }; + +/** + * Returns the position of the first occurrence of an item in an array + * (by strict equality), + * or -1 if the item is not included in the array. + */ +export function indexOf(target: T, list: readonly T[]): number; +export function indexOf(target: T): (list: readonly T[]) => number; + +/** + * Returns all but the last element of a list or string. + */ +export function init(list: readonly T[]): T[]; +export function init(list: string): string; + +/** + * Takes a predicate `pred`, a list `xs`, and a list `ys`, and returns a list + * `xs'` comprising each of the elements of `xs` which is equal to one or more + * elements of `ys` according to `pred`. + * + * `pred` must be a binary function expecting an element from each list. + * + * `xs`, `ys`, and `xs'` are treated as sets, semantically, so ordering should + * not be significant, but since `xs'` is ordered the implementation guarantees + * that its values are in the same order as they appear in `xs`. Duplicates are + * not removed, so `xs'` may contain duplicates if `xs` contains duplicates. + */ + +export function innerJoin(pred: (a: T1, b: T2) => boolean, list1: readonly T1[], list2: readonly T2[]): T1[]; +export function innerJoin(pred: (a: T1, b: T2) => boolean): (list1: readonly T1[], list2: readonly T2[]) => T1[]; +export function innerJoin(pred: (a: T1, b: T2) => boolean, list1: readonly T1[]): (list2: readonly T2[]) => T1[]; + +/** + * Inserts the supplied element into the list, at index index. Note that + * this is not destructive: it returns a copy of the list with the changes. + */ +export function insert(index: number, elt: T, list: readonly T[]): T[]; +export function insert(index: number, elt: T): (list: readonly T[]) => T[]; +export function insert(index: number): (elt: T, list: readonly T[]) => T[]; + +/** + * Inserts the sub-list into the list, at index `index`. _Note that this + * is not destructive_: it returns a copy of the list with the changes. + */ +export function insertAll(index: number, elts: readonly T[], list: readonly T[]): T[]; +export function insertAll(index: number, elts: readonly T[]): (list: readonly T[]) => T[]; +export function insertAll(index: number): (elts: readonly T[], list: readonly T[]) => T[]; + +/** + * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists. + */ +export function intersection(list1: readonly T[], list2: readonly T[]): T[]; +export function intersection(list1: readonly T[]): (list2: readonly T[]) => T[]; + +/** + * Combines two lists into a set (i.e. no duplicates) composed of those + * elements common to both lists. Duplication is determined according + * to the value returned by applying the supplied predicate to two list + * elements. + */ +export function intersectionWith(pred: (a: T, b: T) => boolean, list1: readonly T[], list2: readonly T[]): T[]; + +/** + * Creates a new list with the separator interposed between elements. + */ +export function intersperse(separator: T, list: readonly T[]): T[]; +export function intersperse(separator: T): (list: readonly T[]) => T[]; + +/** + * Transforms the items of the list with the transducer and appends the transformed items to the accumulator + * using an appropriate iterator function based on the accumulator type. + */ +export function into(acc: any, xf: (...a: readonly any[]) => any, list: readonly T[]): T[]; +export function into(acc: any, xf: (...a: readonly any[]) => any): (list: readonly T[]) => T[]; +export function into(acc: any): (xf: (...a: readonly any[]) => any, list: readonly T[]) => T[]; + +/** + * Same as R.invertObj, however this accounts for objects with duplicate values by putting the values into an array. + */ +export function invert(obj: T): { [index: string]: string[] }; + +/** + * Returns a new object with the keys of the given object as values, and the values of the given object as keys. + */ +export function invertObj(obj: { [index: string]: string } | { [index: number]: string }): { [index: string]: string }; + +/** + * Turns a named method with a specified arity into a function that can be called directly + * supplied with arguments and a target object. + * + * The returned function is curried and accepts `arity + 1` parameters where the final + * parameter is the target object. + */ +export function invoker(arity: number, method: string): (...a: readonly any[]) => any; + +/** + * See if an object (`val`) is an instance of the supplied constructor. + * This function will check up the inheritance chain, if any. + */ +export function is(ctor: any, val: any): boolean; +export function is(ctor: any): (val: any) => boolean; + +/** + * Reports whether the list has zero elements. + */ +export function isEmpty(value: any): boolean; + +/** + * Checks if the input value is null or undefined. + */ +export function isNil(value: any): value is null | undefined; + +/** + * Returns a string made by inserting the `separator` between each + * element and concatenating all the elements into a single string. + */ +export function join(x: string, xs: readonly any[]): string; +export function join(x: string): (xs: readonly any[]) => string; + +/** + * Applies a list of functions to a list of values. + */ +export function juxt(fns: [(...a: A) => R1, (...a: A) => R2]): (...a: A) => [R1, R2]; +export function juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3]): (...a: A) => [R1, R2, R3]; +export function juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4]): (...a: A) => [R1, R2, R3, R4]; +export function juxt(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4, (...a: A) => R5]): (...a: A) => [R1, R2, R3, R4, R5]; +export function juxt(fns: Array<(...args: A) => U>): (...args: A) => U[]; + +/** + * Returns a list containing the names of all the enumerable own + * properties of the supplied object. + */ +export function keys(x: T): Array; +export function keys(x: T): string[]; + +/** + * Returns a list containing the names of all the + * properties of the supplied object, including prototype properties. + */ +export function keysIn(obj: T): string[]; + +/** + * Returns the last element from a list. + */ +export function last(str: string): string; +export function last(list: readonly []): undefined; +export function last(list: readonly T[]): T | undefined; + +/** + * Returns the position of the last occurrence of an item (by strict equality) in + * an array, or -1 if the item is not included in the array. + */ +export function lastIndexOf(target: T, list: readonly T[]): number; + +/** + * Returns the number of elements in the array by returning list.length. + */ +export function length(list: readonly T[]): number; + +/** + * Returns a lens for the given getter and setter functions. The getter + * "gets" the value of the focus; the setter "sets" the value of the focus. + * The setter should not mutate the data structure. + */ +export function lens(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens; + +/** + * Creates a lens that will focus on index n of the source array. + */ +export function lensIndex(n: number): Lens; + +/** + * Returns a lens whose focus is the specified path. + * See also view, set, over. + */ +export function lensPath(path: Path): Lens; + +/** + * lensProp creates a lens that will focus on property k of the source object. + */ +export function lensProp(str: string): { + (obj: T): U; + set(val: T, obj: U): V; + /*map(fn: (...a: readonly any[]) => any, obj: T): T*/ +}; + +/** + * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other object that satisfies + * the FantasyLand Apply spec. + */ +export function lift(fn: ((...a: readonly any[]) => any), ...args: readonly any[]): any; + +/** + * "lifts" a function to be the specified arity, so that it may "map over" that many lists, Functions or other + * objects that satisfy the FantasyLand Apply spec. + */ +export function liftN(n: number, fn: ((...a: readonly any[]) => any), ...args: readonly any[]): any; + +/** + * Returns true if the first parameter is less than the second. + */ +export function lt(__: Placeholder, b: number): (a: number) => boolean; +export function lt(__: Placeholder): (b: number, a: number) => boolean; +export function lt(a: number, b: number): boolean; +export function lt(a: number): (b: number) => boolean; + +/** + * Returns true if the first parameter is less than or equal to the second. + */ +export function lte(__: Placeholder, b: number): (a: number) => boolean; +export function lte(__: Placeholder): (b: number, a: number) => boolean; +export function lte(a: number, b: number): boolean; +export function lte(a: number): (b: number) => boolean; + +/** + * Returns a new list, constructed by applying the supplied function to every element of the supplied list. + */ +export function map(fn: (x: T) => U, list: readonly T[]): U[]; +export function map(fn: (x: T) => U): (list: readonly T[]) => U[]; +export function map(fn: (x: T[keyof T & keyof U]) => U[keyof T & keyof U], list: T): U; +export function map(fn: (x: T[keyof T & keyof U]) => U[keyof T & keyof U]): (list: T) => U; +export function map(fn: (x: T) => U, obj: Functor): Functor; // used in functors +export function map(fn: (x: T) => U): (obj: Functor) => Functor; // used in functors + +/** + * The mapAccum function behaves like a combination of map and reduce. + */ +export function mapAccum(fn: (acc: U, value: T) => [U, TResult], acc: U, list: readonly T[]): [U, TResult[]]; +export function mapAccum(fn: (acc: U, value: T) => [U, TResult]): (acc: U, list: readonly T[]) => [U, TResult[]]; +export function mapAccum(fn: (acc: U, value: T) => [U, TResult], acc: U): (list: readonly T[]) => [U, TResult[]]; + +/** + * The mapAccumRight function behaves like a combination of map and reduce. + */ +export function mapAccumRight(fn: (acc: U, value: T) => [U, TResult], acc: U, list: readonly T[]): [U, TResult[]]; +export function mapAccumRight(fn: (acc: U, value: T) => [U, TResult]): (acc: U, list: readonly T[]) => [U, TResult[]]; +export function mapAccumRight(fn: (acc: U, value: T) => [U, TResult], acc: U): (list: readonly T[]) => [U, TResult[]]; + +/** + * Like mapObj, but but passes additional arguments to the predicate function. + */ +export function mapObjIndexed( + fn: (value: T, key: TKey, obj?: Record) => TResult, + obj: Record +): Record; +export function mapObjIndexed( + fn: (value: T, key: TKey, obj?: Record) => TResult +): (obj: Record) => Record; +export function mapObjIndexed( + fn: (value: T, key: string, obj?: { + [key: string]: T + }) => TResult, + obj: { + [key: string]: T } - - interface ArrayLike { - nodeType: number; - } - - type Arity0Fn = () => any; - - type Arity1Fn = (a: any) => any; - - type Arity2Fn = (a: any, b: any) => any; - - interface ObjFunc { - [index: string]: (...a: readonly any[]) => any; - } - - interface ObjFunc2 { - [index: string]: (x: any, y: any) => boolean; - } - - type Pred = (...a: readonly any[]) => boolean; - type SafePred = (...a: readonly T[]) => boolean; - - type ObjPred = (value: any, key: string) => boolean; - - interface Dictionary { - [index: string]: T; - } - - interface CharList extends String { - push(x: string): void; - } - - interface Lens { - (obj: T): U; - set(str: string, obj: T): U; - } - - interface Filter { - (fn: (value: T) => boolean): FilterOnceApplied; - (fn: (value: T) => boolean): (list: readonly T[]) => T[]; - (fn: (value: T) => boolean): (list: Dictionary) => Dictionary; - (fn: (value: T) => boolean, list: readonly T[]): T[]; - (fn: (value: T) => boolean, obj: Dictionary): Dictionary; - } - - type FilterOnceApplied = - >(source: K) => - K extends Array ? U[] : - K extends Dictionary ? Dictionary : - never; - - type Evolve, E extends Evolver> = { - [P in keyof O]: P extends keyof E ? EvolveValue : O[P]; - }; - - type EvolveValue = - E extends (value: V) => any ? ReturnType : - E extends Evolver ? EvolveNestedValue : - never; - - type EvolveNestedValue = - V extends object ? (V extends Evolvable ? Evolve : never) : never; - - interface Evolver { - [key: string]: ((value: any) => any) | Evolver; - } - - // Represents all objects evolvable with Evolver E - type Evolvable = { - [P in keyof E]?: Evolved; - }; - - type Evolved = - T extends (value: infer V) => any ? V : - T extends Evolver ? Evolvable : - never; - - type Placeholder = A.x & {'@@functional/placeholder': true}; - - interface Reduced { - '@@transducer/value': T; - '@@transducer/reduced': true; - } - - type PipeWithFns = [ - (x0: V0) => T - ] | [ - (x0: V0) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ] | [ - (x0: V0) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => T - ]; - - type ComposeWithFns = [ - (x0: V0) => T - ] | [ - (x: any) => T, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ] | [ - (x: any) => T, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: any) => any, - (x: V0) => any - ]; - - interface AssocPartialOne { - (val: T): (obj: U) => Record & U; - (val: T, obj: U): Record & U; - } - - interface Static { - /** - * Placeholder. When used with functions like curry, or op, the second argument is applied to the second - * position, and it returns a function waiting for its first argument. - */ - __: Placeholder; /* This is used in examples throughout the docs, but I it only seems to be directly explained here: https://ramdajs.com/0.9/docs/#op */ - - /** - * Adds two numbers (or strings). Equivalent to a + b but curried. - */ - add(a: number, b: number): number; - add(a: string, b: string): string; - add(a: number): (b: number) => number; - add(a: string): (b: string) => string; - - /** - * Creates a new list iteration function from an existing one by adding two new parameters to its callback - * function: the current index, and the entire list. - */ - addIndex(fn: (f: (item: T) => U, list: readonly T[]) => U[]): F.Curry<(a: (item: T, idx: number, list?: T[]) => U, b: readonly T[]) => U[]>; - /* Special case for forEach */ - addIndex(fn: (f: (item: T) => void, list: readonly T[]) => T[]): F.Curry<(a: (item: T, idx: number, list?: T[]) => void, b: readonly T[]) => T[]>; - /* Special case for reduce */ - addIndex(fn: (f: (acc: U, item: T) => U, aci: U, list: readonly T[]) => U): F.Curry<(a: (acc: U, item: T, idx: number, list?: T[]) => U, b: U, c: readonly T[]) => U>; - - /** - * Applies a function to the value at the given index of an array, returning a new copy of the array with the - * element at the given index replaced with the result of the function application. - */ - adjust(index: number, fn: (a: T) => T, list: readonly T[]): T[]; - adjust(index: number, fn: (a: T) => T): (list: readonly T[]) => T[]; - - /** - * Returns true if all elements of the list match the predicate, false if there are any that don't. - */ - all(fn: (a: T) => boolean, list: readonly T[]): boolean; - all(fn: (a: T) => boolean): (list: readonly T[]) => boolean; - - /** - * Given a list of predicates, returns a new predicate that will be true exactly when all of them are. - */ - allPass(preds: readonly Pred[]): Pred; - - /** - * Returns a function that always returns the given value. - */ - always(val: T): () => T; - - /** - * A function that returns the first argument if it's falsy otherwise the second argument. Note that this is - * NOT short-circuited, meaning that if expressions are passed they are both evaluated. - */ - and any); } | number | boolean | string | null>(fn1: T, val2: any): boolean; - and any); } | number | boolean | string | null>(fn1: T): (val2: any) => boolean; - - /** - * Returns true if at least one of elements of the list match the predicate, false otherwise. - */ - any(fn: (a: T) => boolean, list: readonly T[]): boolean; - any(fn: (a: T) => boolean): (list: readonly T[]) => boolean; - - /** - * Given a list of predicates returns a new predicate that will be true exactly when any one of them is. - */ - anyPass(preds: Array>): SafePred; - - /** - * ap applies a list of functions to a list of values. - */ - ap(fns: Array<((a: T) => U)>, vs: readonly T[]): U[]; - ap(fns: Array<((a: T) => U)>): (vs: readonly T[]) => U[]; - ap( - fn: (x1: X1, x0: X0) => R, - fn1: (x1: X1) => X0 - ): (x1: X1) => R; - - /** - * Returns a new list, composed of n-tuples of consecutive elements If n is greater than the length of the list, - * an empty list is returned. - */ - aperture(n: 1, list: readonly T[]): Array<[T]>; - aperture(n: 2, list: readonly T[]): Array<[T, T]>; - aperture(n: 3, list: readonly T[]): Array<[T, T, T]>; - aperture(n: 4, list: readonly T[]): Array<[T, T, T, T]>; - aperture(n: 5, list: readonly T[]): Array<[T, T, T, T, T]>; - aperture(n: 6, list: readonly T[]): Array<[T, T, T, T, T, T]>; - aperture(n: 7, list: readonly T[]): Array<[T, T, T, T, T, T, T]>; - aperture(n: 8, list: readonly T[]): Array<[T, T, T, T, T, T, T, T]>; - aperture(n: 9, list: readonly T[]): Array<[T, T, T, T, T, T, T, T, T]>; - aperture(n: 10, list: readonly T[]): Array<[T, T, T, T, T, T, T, T, T, T]>; - aperture(n: number, list: readonly T[]): T[][]; - aperture(n: number): (list: readonly T[]) => T[][]; - - /** - * Returns a new list containing the contents of the given list, followed by the given element. - */ - append(el: T, list: readonly T[]): T[]; - append(el: T): (list: readonly T[]) => T[]; - - /** - * Applies function fn to the argument list args. This is useful for creating a fixed-arity function from - * a variadic function. fn should be a bound function if context is significant. - */ - apply(fn: (arg0: T, ...args: readonly T[]) => TResult, args: readonly U[]): TResult; - apply(fn: (arg0: T, ...args: readonly T[]) => TResult): (args: readonly U[]) => TResult; - - /** - * Given a spec object recursively mapping properties to functions, creates a function producing an object - * of the same structure, by mapping each property to the result of calling its associated function with - * the supplied arguments. - */ - applySpec any>>( - obj: Obj - ): ( - ...args: Parameters> - ) => { [Key in keyof Obj]: ReturnType }; - applySpec(obj: any): (...args: readonly any[]) => T; - - /** - * Takes a value and applies a function to it. - * This function is also known as the thrush combinator. - */ - applyTo(el: T, fn: (t: T) => U): U; - applyTo(el: T): (fn: (t: T) => U) => U; - - /** - * Makes an ascending comparator function out of a function that returns a value that can be compared with < and >. - */ - ascend(fn: (obj: T) => any, a: T, b: T): number; - ascend(fn: (obj: T) => any): (a: T, b: T) => number; - - /** - * Makes a shallow clone of an object, setting or overriding the specified property with the given value. - */ - assoc(__: Placeholder, val: T, obj: U): (prop: K) => Record & U; - assoc(prop: K, __: Placeholder, obj: U): (val: T) => Record & U; - assoc(prop: K, val: T, obj: U): Record & U; - assoc(prop: K, val: T): (obj: U) => Record & U; - assoc(prop: K): AssocPartialOne; - - /** - * Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and - * placing the specific value at the tail end of that path. - */ - assocPath(__: Placeholder, val: T, obj: U): (path: Path) => U; - assocPath(path: Path, __: Placeholder, obj: U): (val: T) => U; - assocPath(path: Path, val: T, obj: U): U; - assocPath(path: Path, val: T): (obj: U) => U; - assocPath(path: Path): F.Curry<(a: T, b: U) => U>; - - /** - * Wraps a function of any arity (including nullary) in a function that accepts exactly 2 - * parameters. Any extraneous parameters will not be passed to the supplied function. - */ - binary(fn: (...args: readonly any[]) => any): (...a: readonly any[]) => any; - - /** - * Creates a function that is bound to a context. Note: R.bind does not provide the additional argument-binding - * capabilities of Function.prototype.bind. - */ - bind(fn: (...args: readonly any[]) => any, thisObj: T): (...args: readonly any[]) => any; - - /** - * A function wrapping calls to the two functions in an && operation, returning the result of the first function - * if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning - * that the second function will not be invoked if the first returns a false-y value. - */ - both(pred1: Pred, pred2: Pred): Pred; - both(pred1: Pred): (pred2: Pred) => Pred; - - /** - * Returns the result of calling its first argument with the remaining arguments. This is occasionally useful - * as a converging function for R.converge: the left branch can produce a function while the right branch - * produces a value to be passed to that function as an argument. - */ - call(fn: (...args: readonly any[]) => (...args: readonly any[]) => any, ...args: readonly any[]): any; - - /** - * `chain` maps a function over a list and concatenates the results. - * This implementation is compatible with the Fantasy-land Chain spec - */ - chain(fn: (n: T) => U[], list: readonly T[]): U[]; - chain(fn: (n: T) => U[]): (list: readonly T[]) => U[]; - chain(fn: (x0: X0, x1: X1) => R, fn1: (x1: X1) => X0): (x1: X1) => R; - - /** - * Restricts a number to be within a range. - * Also works for other ordered types such as Strings and Date - */ - clamp(min: T, max: T, value: T): T; - clamp(min: T, max: T): (value: T) => T; - clamp(min: T): (max: T, value: T) => T; - clamp(min: T): (max: T) => (value: T) => T; - - /** - * Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates. - */ - clone(value: T): T; - clone(value: readonly T[]): T[]; - - /** - * Makes a comparator function out of a function that reports whether the first element is less than the second. - */ - // comparator(pred: (a: any, b: any) => boolean): (x: number, y: number) => number; - comparator(pred: (a: T, b: T) => boolean): (x: T, y: T) => number; - - /** - * Takes a function f and returns a function g such that: - * - applying g to zero or more arguments will give true if applying the same arguments to f gives - * a logical false value; and - * - applying g to zero or more arguments will give false if applying the same arguments to f gives - * a logical true value. - */ - complement(pred: (...args: readonly any[]) => boolean): (...args: readonly any[]) => boolean; - - /** - * Performs right-to-left function composition. The rightmost function may have any arity; the remaining - * functions must be unary. - */ - - // generic rest parameters in TS 3.0 allows writing a single variant for any number of Vx - // compose(fn0: (...args: V) => T1): (...args: V) => T1; - // compose(fn1: (x: T1) => T2, fn0: (...args: V) => T1): (...args: V) => T2; - // but requiring TS>=3.0 sounds like a breaking change, so just leaving a comment for the future - - compose(fn0: () => T1): () => T1; - compose(fn0: (x0: V0) => T1): (x0: V0) => T1; - compose(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1; - compose(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1; - - compose(fn1: (x: T1) => T2, fn0: () => T1): () => T2; - compose(fn1: (x: T1) => T2, fn0: (x0: V0) => T1): (x0: V0) => T2; - compose(fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T2; - compose(fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T2; - - compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T3; - compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T3; - compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T3; - compose(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T3; - - compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T4; - compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T4; - compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T4; - compose(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T4; - - compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T5; - compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T5; - compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T5; - compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T5; - - compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): () => T6; - compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T6; - compose( - fn5: (x: T5) => T6, - fn4: (x: T4) => T5, - fn3: (x: T3) => T4, - fn2: (x: T2) => T3, - fn1: (x: T1) => T2, - fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T6; - compose( - fn5: (x: T5) => T6, - fn4: (x: T4) => T5, - fn3: (x: T3) => T4, - fn2: (x: T2) => T3, - fn1: (x: T1) => T2, - fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6; - - /** - * Returns the right-to-left Kleisli composition of the provided functions, each of which must return a value of a type supported by chain. - * The typings only support arrays for now. - * All functions must be unary. - * R.composeK(h, g, f) is equivalent to R.compose(R.chain(h), R.chain(g), f). - * - * @deprecated since 0.26 in favor of composeWith(chain) - */ - composeK( - fn0: (x0: V0) => T1[]): (x0: V0) => T1[]; - composeK( - fn1: (x: T1) => T2[], - fn0: (x0: V0) => T1[]): (x0: V0) => T2[]; - composeK( - fn2: (x: T2) => T3[], - fn1: (x: T1) => T2[], - fn0: (x: V0) => T1[]): (x: V0) => T3[]; - composeK( - fn3: (x: T3) => T4[], - fn2: (x: T2) => T3[], - fn1: (x: T1) => T2[], - fn0: (x: V0) => T1[]): (x: V0) => T4[]; - composeK( - fn4: (x: T4) => T5[], - fn3: (x: T3) => T4[], - fn2: (x: T2) => T3[], - fn1: (x: T1) => T2[], - fn0: (x: V0) => T1[]): (x: V0) => T5[]; - composeK( - fn5: (x: T5) => T6[], - fn4: (x: T4) => T5[], - fn3: (x: T3) => T4[], - fn2: (x: T2) => T3[], - fn1: (x: T1) => T2[], - fn0: (x: V0) => T1[]): (x: V0) => T6[]; - - /** - * Performs right-to-left composition of one or more Promise-returning functions. - * All functions must be unary. - * - * @deprecated since 0.26 in favor of composeWith(then) - */ - composeP( - fn0: (x0: V0) => Promise): (x0: V0) => Promise; - composeP( - fn1: (x: T1) => Promise, - fn0: (x0: V0) => Promise): (x0: V0) => Promise; - composeP( - fn2: (x: T2) => Promise, - fn1: (x: T1) => Promise, - fn0: (x: V0) => Promise): (x: V0) => Promise; - composeP( - fn3: (x: T3) => Promise, - fn2: (x: T2) => Promise, - fn1: (x: T1) => Promise, - fn0: (x: V0) => Promise): (x: V0) => Promise; - composeP( - fn4: (x: T4) => Promise, - fn3: (x: T3) => Promise, - fn2: (x: T2) => Promise, - fn1: (x: T1) => Promise, - fn0: (x: V0) => Promise): - (x: V0) => Promise; - composeP( - fn5: (x: T5) => Promise, - fn4: (x: T4) => Promise, - fn3: (x: T3) => Promise, - fn2: (x: T2) => Promise, - fn1: (x: T1) => Promise, - fn0: (x: V0) => Promise): - (x: V0) => Promise; - - /** - * Performs right-to-left function composition using transforming function. - * With the current typings, all functions must be unary. - */ - composeWith(composer: (a: any) => any, fns: ComposeWithFns): (x0: V0) => T; - composeWith(composer: (a: any) => any): (fns: ComposeWithFns) => (x: V0) => T; - - /** - * Returns a new list consisting of the elements of the first list followed by the elements - * of the second. - */ - concat(placeholder: Placeholder): (list2: readonly T[], list1: readonly T[]) => T[]; - concat(placeholder: Placeholder, list2: readonly T[]): (list1: readonly T[]) => T[]; - concat(list1: readonly T[], list2: readonly T[]): T[]; - concat(list1: readonly T[]): (list2: readonly T[]) => T[]; - concat(list1: string, list2: string): string; - concat(list1: string): (list2: string) => string; - - /** - * Returns a function, fn, which encapsulates if/else-if/else logic. R.cond takes a list of [predicate, transform] pairs. - * All of the arguments to fn are applied to each of the predicates in turn until one returns a "truthy" value, at which - * point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates - * matches, fn returns undefined. - */ - cond(fns: Array<[Pred, (...a: readonly any[]) => any]>): (...a: readonly any[]) => any; - cond(fns: Array<[SafePred, (...a: readonly A[]) => B]>): (...a: readonly A[]) => B; - - /** - * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. - */ - construct(constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: A) => T; - - /** - * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. - * The arity of the function returned is specified to allow using variadic constructor functions. - */ - constructN(n: number, constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: Partial) => T; - - /** - * Returns `true` if the specified item is somewhere in the list, `false` otherwise. - * Equivalent to `indexOf(a)(list) > -1`. Uses strict (`===`) equality checking. - * - * @deprecated since 0.26 in favor of includes - */ - contains(__: Placeholder, list: string): (a: string) => boolean; - contains(__: Placeholder, list: readonly T[]): (a: T) => boolean; - contains(__: Placeholder): (list: string, a: string) => boolean; - contains(__: Placeholder): (list: readonly T[], a: T) => boolean; - contains(a: string, list: string): boolean; - contains(a: T, list: readonly T[]): boolean; - contains(a: string): (list: string) => boolean; - contains(a: T): (list: readonly T[]) => boolean; - - /** - * 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. - */ - converge(after: ((...a: readonly any[]) => any), fns: Array<((...a: readonly any[]) => any)>): (...a: readonly any[]) => any; - - /** - * Counts the elements of a list according to how many match each value - * of a key generated by the supplied function. Returns an object - * mapping the keys produced by `fn` to the number of occurrences in - * the list. Note that all keys are coerced to strings because of how - * JavaScript objects work. - */ - countBy(fn: (a: T) => string | number, list: readonly T[]): { [index: string]: number }; - countBy(fn: (a: T) => string | number): (list: readonly T[]) => { [index: string]: number }; - - /** - * Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. - * First, its arguments needn't be provided one at a time. - */ - curry any>(f: F): F.Curry; - - /** - * Returns a curried equivalent of the provided function, with the specified arity. The curried function has - * two unusual capabilities. First, its arguments needn't be provided one at a time. - */ - curryN(length: number, fn: (...args: readonly any[]) => any): (...a: readonly any[]) => any; - - /** - * Decrements its argument. - */ - dec(n: number): number; - - /** - * Returns the second argument if it is not null or undefined. If it is null or undefined, the - * first (default) argument is returned. - */ - defaultTo(a: T, b: U | null | undefined): T | U; - defaultTo(a: T): (b: U | null | undefined) => T | U; - - /** - * Makes a descending comparator function out of a function that returns a value that can be compared with < and >. - */ - descend(fn: (obj: T) => any, a: T, b: T): number; - descend(fn: (obj: T) => any): (a: T, b: T) => number; - - /** - * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. - */ - difference(list1: readonly T[], list2: readonly T[]): T[]; - difference(list1: readonly T[]): (list2: readonly T[]) => T[]; - - /** - * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. - * Duplication is determined according to the value returned by applying the supplied predicate to two list - * elements. - */ - differenceWith(pred: (a: T1, b: T2) => boolean, list1: readonly T1[], list2: readonly T2[]): T1[]; - differenceWith(pred: (a: T1, b: T2) => boolean): (list1: readonly T1[], list2: readonly T2[]) => T1[]; - differenceWith(pred: (a: T1, b: T2) => boolean, list1: readonly T1[]): (list2: readonly T2[]) => T1[]; - - /* - * Returns a new object that does not contain a prop property. - */ - // It seems impossible to infer the return type, so this may to be specified explicitely - dissoc(prop: string, obj: any): T; - dissoc(prop: string): (obj: any) => U; - - /** - * Makes a shallow clone of an object, omitting the property at the given path. - */ - dissocPath(path: Path, obj: any): T; - dissocPath(path: Path): (obj: any) => T; - - /** - * Divides two numbers. Equivalent to a / b. - */ - divide(__: Placeholder, b: number): (a: number) => number; - divide(__: Placeholder): (b: number, a: number) => number; - divide(a: number, b: number): number; - divide(a: number): (b: number) => number; - - /** - * Returns a new list containing all but the first n elements of the given list. - */ - drop(n: number, xs: readonly T[]): T[]; - drop(n: number, xs: string): string; - drop(n: number): { - (xs: string): string; - (xs: readonly T[]): T[]; - }; - - /** - * Returns a list containing all but the last n elements of the given list. - */ - dropLast(n: number, xs: readonly T[]): T[]; - dropLast(n: number, xs: string): string; - dropLast(n: number): { - (xs: readonly T[]): T[]; - (xs: string): string; - }; - - /** - * Returns a new list containing all but last then elements of a given list, passing each value from the - * right to the supplied predicate function, skipping elements while the predicate function returns true. - */ - dropLastWhile(fn: (a: T) => boolean, list: readonly T[]): T[]; - dropLastWhile(fn: (a: T) => boolean): (list: readonly T[]) => T[]; - - /** - * Returns a new list without any consecutively repeating elements. R.equals is used to determine equality. - */ - dropRepeats(list: readonly T[]): T[]; - - /** - * Returns a new list without any consecutively repeating elements. - * Equality is determined by applying the supplied predicate to each pair of consecutive elements. - * The first element in a series of equal elements will be preserved. - */ - dropRepeatsWith(predicate: (left: T, right: T) => boolean, list: readonly T[]): T[]; - dropRepeatsWith(predicate: (left: T, right: T) => boolean): (list: readonly T[]) => T[]; - - /** - * Returns a new list containing the last n elements of a given list, passing each value to the supplied - * predicate function, skipping elements while the predicate function returns true. - */ - dropWhile(fn: (a: T) => boolean, list: readonly T[]): T[]; - dropWhile(fn: (a: T) => boolean): (list: readonly T[]) => T[]; - - /** - * A function wrapping calls to the two functions in an || operation, returning the result of the first - * function if it is truth-y and the result of the second function otherwise. Note that this is - * short-circuited, meaning that the second function will not be invoked if the first returns a truth-y value. - */ - either(pred1: Pred, pred2: Pred): Pred; - either(pred1: Pred): (pred2: Pred) => Pred; - - /** - * Returns the empty value of its argument's type. Ramda defines the empty value of Array ([]), Object ({}), - * String (''), and Arguments. Other types are supported if they define .empty and/or .prototype.empty. - * Dispatches to the empty method of the first argument, if present. - */ - empty(x: T): T; - - /** - * Checks if a list ends with the provided values - */ - endsWith(a: string, list: string): boolean; - endsWith(a: string): (list: string) => boolean; - endsWith(a: T | readonly T[], list: readonly T[]): boolean; - endsWith(a: T | readonly T[]): (list: readonly T[]) => boolean; - - /** - * Takes a function and two values in its domain and returns true if the values map to the same value in the - * codomain; false otherwise. - */ - eqBy(fn: (a: T) => U, a: T, b: T): boolean; - eqBy(fn: (a: T) => U, a: T): (b: T) => boolean; - eqBy(fn: (a: T) => U): F.Curry<(a: T, b: T) => boolean>; - - /** - * Reports whether two functions have the same value for the specified property. - */ - eqProps(prop: string, obj1: T, obj2: U): boolean; - eqProps