import { Kind, URIS, URIS2, URIS3, Kind2, Kind3, HKT } from 'fp-ts/HKT'; import { Subset } from './Subset'; import { PipeableFunctorWithIndex1, PipeableChain1, PipeableFilterableWithIndex1, PipeableFoldable1, PipeableAlt1, PipeableExtend1 } from 'fp-ts/pipeable'; import { Monoid } from 'fp-ts/Monoid'; import { Monad1 } from 'fp-ts/Monad'; import { Applicative, Applicative1, Applicative2, Applicative3, Applicative2C } from 'fp-ts/Applicative'; import { Unfoldable1 } from 'fp-ts/Unfoldable'; import * as E from 'fp-ts/Either'; import * as O from 'fp-ts/Option'; import { Ord } from 'fp-ts/Ord'; import { Eq } from 'fp-ts/Eq'; import { Show } from 'fp-ts/Show'; import { Alternative1 } from 'fp-ts/Alternative'; import { Witherable1 } from 'fp-ts/Witherable'; import { TraversableWithIndex1 } from 'fp-ts/TraversableWithIndex'; declare type EnforceNonEmptyRecord = keyof R extends never ? never : R; export interface GroupOption { getValue: (a: A) => B; show: Show; } export interface Typeclass extends Subset, PipeableChain1 { /** * Returns a new `Collection` with values passed through a mapper function. * * @example * import { mapWithIndex } from 'fp-ts/List' * * assert.deepStrictEqual(mapWithIndex((i,a)=>a+i)([1, 2, 3]), [1, 3, 5]) * * @since 0.5.0 */ readonly mapWithIndex: PipeableFunctorWithIndex1['mapWithIndex']; /** * Returns a new `Collection` with values passed through a mapper function. * * @example * import { map } from 'fp-ts/List' * * assert.deepStrictEqual(map(a=>a+1)([1, 2, 3]), [2, 3, 4]) * * @since 0.5.0 */ readonly map: PipeableChain1['map']; readonly ap: PipeableChain1['ap']; readonly apFirst: PipeableChain1['apFirst']; readonly apSecond: PipeableChain1['apSecond']; readonly zero: Alternative1['zero']; readonly alt: PipeableAlt1['alt']; readonly chain: PipeableChain1['chain']; readonly chainFirst: PipeableChain1['chainFirst']; readonly flatten: PipeableChain1['flatten']; readonly reduce: PipeableFoldable1['reduce']; readonly foldMap: PipeableFoldable1['foldMap']; readonly reduceRight: PipeableFoldable1['reduceRight']; foldM(M: Monad1): (fa: Kind, b: B, f: (b: B, a: A) => Kind) => Kind; traverse_(M: Applicative3): (fa: Kind, f: (a: A) => Kind3) => Kind3; traverse_(M: Applicative2): (fa: Kind, f: (a: A) => Kind2) => Kind2; traverse_(M: Applicative2C): (fa: Kind, f: (a: A) => Kind2) => Kind2; traverse_(M: Applicative1): (fa: Kind, f: (a: A) => Kind) => Kind; traverse_(M: Applicative): (fa: Kind, f: (a: A) => HKT) => HKT; traverse_(M: Applicative): (fa: Kind, f: (a: A) => HKT) => HKT; of: (a: A) => Kind; sequenceT>>(...t: T & { 0: Kind; }): Kind; sequenceS>>(r: EnforceNonEmptyRecord): Kind] ? A : never; }>; sequenceS>>(r: EnforceNonEmptyRecord): Kind; readonly unfold: (b: B, f: (b: B) => O.Option<[A, B]>) => Kind; readonly reduceWithIndex: (b: B, f: (i: I, b: B, a: A) => B) => (fa: Kind) => B; readonly foldMapWithIndex: (M: Monoid) => (f: (i: I, a: A) => M) => (fa: Kind) => M; readonly reduceRightWithIndex: (b: B, f: (i: I, a: A, b: B) => B) => (fa: Kind) => B; readonly filter: PipeableFilterableWithIndex1['filter']; readonly filterMap: PipeableFilterableWithIndex1['filterMap']; readonly partition: PipeableFilterableWithIndex1['partition']; readonly partitionMap: PipeableFilterableWithIndex1['partitionMap']; readonly compact: PipeableFilterableWithIndex1['compact']; readonly separate: PipeableFilterableWithIndex1['separate']; readonly sequence: Witherable1['sequence']; readonly traverse: Witherable1['traverse']; readonly wilt: Witherable1['wilt']; readonly wither: Witherable1['wither']; readonly traverseWithIndex: TraversableWithIndex1['traverseWithIndex']; readonly filterWithIndex: PipeableFilterableWithIndex1['filterWithIndex']; readonly filterMapWithIndex: PipeableFilterableWithIndex1['filterMapWithIndex']; readonly partitionWithIndex: PipeableFilterableWithIndex1['partitionWithIndex']; readonly partitionMapWithIndex: PipeableFilterableWithIndex1['partitionMapWithIndex']; readonly extend: PipeableExtend1['extend']; readonly duplicate: PipeableExtend1['duplicate']; /** * Extracts from an list of `Either` all the `Right` elements. All the `Right` elements are extracted in order * * @example * import { rights } from 'fp-ts/List' * import { right, left } from 'fp-ts/Either' * * assert.deepStrictEqual(rights([right(1), left('foo'), right(2)]), [1, 2]) * * @since 0.5.0 */ rights(as: Kind>): Kind; /** * Extracts from an list of `Either` all the `Left` elements. All the `Left` elements are extracted in order * * @example * import { lefts } from 'fp-ts/List' * import { left, right } from 'fp-ts/Either' * * assert.deepStrictEqual(lefts([right(1), left('foo'), right(2)]), ['foo']) * * @since 0.5.0 */ lefts(as: Kind>): Kind; /** * Sort the elements of an list in increasing order, creating a new list * * @example * import { sort } from 'fp-ts/List' * import { ordNumber } from 'fp-ts/Ord' * * assert.deepStrictEqual(sort(ordNumber)([3, 2, 1]), [1, 2, 3]) * * @since 0.5.0 */ sort(O: Ord): (as: Kind) => Kind; /** * Sort the elements of an list in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`, * etc... * * @example * import { sortBy } from 'fp-ts/List' * import { ord, ordString, ordNumber } from 'fp-ts/Ord' * * interface Person { * name: string * age: number * } * const byName = ord.contramap(ordString, (p: Person) => p.name) * const byAge = ord.contramap(ordNumber, (p: Person) => p.age) * * const sortByNameByAge = sortBy([byName, byAge]) * * const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }] * assert.deepStrictEqual(sortByNameByAge(persons), [ * { name: 'a', age: 1 }, * { name: 'b', age: 2 }, * { name: 'b', age: 3 }, * { name: 'c', age: 2 } * ]) * * @since 0.5.0 */ sortBy(ords: Array>): (as: Kind) => Kind; /** * Returns the maximum value in this `collection`. * If any values are comparatively equivalent, the first one found will be returned. * * @example * import { max } from 'fp-ts/List' * import { ordNumber } from 'fp-ts/Ord' * * assert.deepStrictEqual(max(ordNumber)([3, 2, 1]), 3) * * @since 0.5.0 */ max(O: Ord): (as: Kind) => O.Option; /** * Like max, but also accepts a comparatorValueMapper which allows for comparing by more sophisticated means: * Compare the elements of an list in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`, * etc... * * @example * import { maxBy } from 'fp-ts/List' * import { ord, ordString, ordNumber } from 'fp-ts/Ord' * * interface Person { * name: string * age: number * } * const byName = ord.contramap(ordString, (p: Person) => p.name) * const byAge = ord.contramap(ordNumber, (p: Person) => p.age) * * const maxByNameByAge = maxBy([byName, byAge]) * * const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }] * assert.deepStrictEqual(sortByNameByAge(persons), * { name: 'c', age: 2 } * ) * * @since 0.5.0 */ maxBy(ords: Array>): (as: Kind) => O.Option; /** * Returns the minimum value in this `collection`. * If any values are comparatively equivalent, the first one found will be returned. * * @example * import { min } from 'fp-ts/List' * import { ordNumber } from 'fp-ts/Ord' * * assert.deepStrictEqual(min(ordNumber)([3, 2, 1]), 1) * * @since 0.5.0 */ min(O: Ord): (as: Kind) => O.Option; /** * Like min, but also accepts a Array which allows for comparing by more sophisticated means: * Compare the elements of an list in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`, * etc... * * @example * import { minBy } from 'fp-ts/List' * import { ord, ordString, ordNumber } from 'fp-ts/Ord' * * interface Person { * name: string * age: number * } * const byName = ord.contramap(ordString, (p: Person) => p.name) * const byAge = ord.contramap(ordNumber, (p: Person) => p.age) * * const minByNameByAge = minBy([byName, byAge]) * * const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }] * assert.deepStrictEqual(sortByNameByAge(persons), * { name: 'a', age: 1 } * ) * * @since 0.5.0 */ minBy(ords: Array>): (as: Kind) => O.Option; /** * Apply a function to pairs of elements at the same index in two arrays, collecting the results in a new list. * * If one input list is short, excess elements of the longer list are discarded. * * @example * import { zipWith } from 'fp-ts/List' * * assert.deepStrictEqual(zipWith([1, 2, 3], ['a', 'b', 'c', 'd'], (n, s) => s + n), ['a1', 'b2', 'c3']) * * @since 0.5.0 */ zipWith(fa: Kind, fb: Kind, f: (a: A, b: B) => C): Kind; /** * Takes two arrays and returns an list of corresponding pairs. If one input list is short, excess elements of the * longer list are discarded * * @example * import { zip } from 'fp-ts/List' * * assert.deepStrictEqual(zip([1, 2, 3], ['a', 'b', 'c', 'd']), [[1, 'a'], [2, 'b'], [3, 'c']]) * * @since 0.5.0 */ zip(fa: Kind, fb: Kind): Kind; /** * The function is reverse of `zip`. Takes an list of pairs and return two corresponding arrays * * @example * import { unzip } from 'fp-ts/List' * * assert.deepStrictEqual(unzip([[1, 'a'], [2, 'b'], [3, 'c']]), [[1, 2, 3], ['a', 'b', 'c']]) * * @since 0.5.0 */ unzip(as: Kind): [Kind, Kind]; /** * Rotate an list to the right by `n` steps * * @example * import { rotate } from 'fp-ts/List' * * assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3]) * * @since 0.5.0 */ rotate(n: number): (as: Kind) => Kind; /** * Test if a value is a member of an list. Takes a `Eq` as a single * argument which returns the function to use to search for a value of type `A` in * an list of type `Kind`. * * @example * import { includes } from 'fp-ts/List' * import { eqNumber } from 'fp-ts/Eq' * * assert.strictEqual(includes(eqNumber)(1, [1, 2, 3]), true) * assert.strictEqual(includes(eqNumber)(4, [1, 2, 3]), false) * * @since 0.5.0 */ includes(E: Eq): (a: A, as: Kind) => boolean; /** * Remove duplicates from an list, keeping the first occurance of an element. * * @example * import { uniq } from 'fp-ts/List' * import { eqNumber } from 'fp-ts/Eq' * * assert.deepStrictEqual(uniq(eqNumber)([1, 2, 1]), [1, 2]) * * @since 0.5.0 */ uniq(E: Eq): (as: Kind) => Kind; /** * Creates an list of unique values, in order, from all given arrays using a `Eq` for equality comparisons * * @example * import { union } from 'fp-ts/List' * import { eqNumber } from 'fp-ts/Eq' * * assert.deepStrictEqual(union(eqNumber)([1, 2], [2, 3]), [1, 2, 3]) * * @since 0.5.0 */ union(E: Eq): (xs: Kind, ys: Kind) => Kind; /** * Creates an list of unique values that are included in all given arrays using a `Eq` for equality * comparisons. The order and references of result values are determined by the first list. * * @example * import { intersection } from 'fp-ts/List' * import { eqNumber } from 'fp-ts/Eq' * * assert.deepStrictEqual(intersection(eqNumber)([1, 2], [2, 3]), [2]) * * @since 0.5.0 */ intersection(E: Eq): (xs: Kind, ys: Kind) => Kind; /** * Creates an list of list values not included in the other given list using a `Eq` for equality * comparisons. The order and references of result values are determined by the first list. * * @example * import { difference } from 'fp-ts/List' * import { eqNumber } from 'fp-ts/Eq' * * assert.deepStrictEqual(difference(eqNumber)([1, 2], [2, 3]), [1]) * * @since 0.5.0 */ difference(E: Eq): (xs: Kind, ys: Kind) => Kind; toRecord, K extends keyof A>(key: K): (as: Kind) => Record>; fromRecord(key: K): >(as: Record) => Kind; scanLeft(b: B, f: (b: B, a: A) => B): (as: Kind) => Kind; /** * Fold an list from the right, keeping all intermediate results instead of only the final result * * @example * import { scanRight } from 'fp-ts/List' * * assert.deepStrictEqual(scanRight(10, (a: number, b) => b - a)([1, 2, 3]), [4, 5, 7, 10]) * * @since 0.5.0 */ scanRight(b: B, f: (a: A, b: B) => B): (as: Kind) => Kind; /** * Array comprehension * * ``` * [ f(x, y, ...) | x ← xs, y ← ys, ..., g(x, y, ...) ] * ``` * * @example * import { comprehension } from 'fp-ts/Array' * import { tuple } from 'fp-ts/function' * * assert.deepStrictEqual(comprehension([[1, 2, 3], ['a', 'b']], tuple, (a, b) => (a + b.length) % 2 === 0), [ * [1, 'a'], * [1, 'b'], * [3, 'a'], * [3, 'b'] * ]) * * @since 2.0.0 */ comprehension(input: [Kind, Kind, Kind, Kind], f: (a: A, b: B, c: C, d: D) => R, g?: (a: A, b: B, c: C, d: D) => boolean): Kind; comprehension(input: [Kind, Kind, Kind], f: (a: A, b: B, c: C) => R, g?: (a: A, b: B, c: C) => boolean): Kind; comprehension(input: [Kind], f: (a: A) => R, g?: (a: A) => boolean): Kind; comprehension(input: [Kind, Kind], f: (a: A, b: B) => R, g?: (a: A, b: B) => boolean): Kind; comprehension(input: [Kind], f: (a: A) => boolean, g?: (a: A) => R): Kind; comprehension(input: [F, Kind], f: (...xs: any[]) => R, g: (...xs: any[]) => boolean): Kind; /** * A useful recursion pattern for processing an `collection` to produce a new `collection`, often used for "chopping" up the input * `collection`. Typically chop is called with some function that will consume an initial prefix of the array and produce a * value and the rest of the array. * * @example * import { Eq, eqNumber } from 'fp-ts/Eq' * import { chop, spanLeft } from 'fp-ts/Array' * * const group = (S: Eq): ((as: Array) => Array>) => { * return chop(as => { * const { init, rest } = spanLeft((a: A) => S.equals(a, as[0]))(as) * return [init, rest] * }) * } * assert.deepStrictEqual(group(eqNumber)([1, 1, 2, 3, 3, 4]), [[1, 1], [2], [3, 3], [4]]) * * @since 2.0.0 */ chop(f: (as: Kind) => [B, Kind]): (as: Kind) => Kind; foldLeft(onNil: () => B, onCons: (head: A, tail: Kind) => B): (as: Kind) => B; foldRight(onNil: () => B, onCons: (init: Kind, last: A) => B): (as: Kind) => B; /** * Group by a mehtod * @example * pipe( * from([1, 1, 2, 1, 1, 3, 3, 4]), * groupByOption({ getValue: (a: number) => a, show: showNumber }), * expect({ * '1': from([1, 1, 1, 1]), * '2': from([2]), * '3': from([3, 3]), * '4': from([4]) * }).toEqual * ) * */ groupBy({ getValue, show: { show } }: GroupOption): (as: Kind) => Record>; getShow(S: Show): Show>; getEq: (eq: Eq) => Eq>; getMonoid: () => Monoid>; getOrd: (O: Ord) => Ord>; collection: Monad1 & Unfoldable1 & Alternative1 & Witherable1 & TraversableWithIndex1; } export declare function initTypeclass(option: Subset): Typeclass; export {};