/** * Subset Collection Interface * @desczh * 子集接口 * @file * @since 0.2.0 */ import { Kind, URIS } from 'fp-ts/HKT'; import { Option } from 'fp-ts/Option'; import { Predicate, Refinement } from 'fp-ts/function'; import { IndexWriterCollection } from './IndexWriterCollection'; export interface SubsetCollectionInput { /** * Returns a new Collection of the same type representing a portion of this * Collection from start up to but not including end. * * If begin is negative, it is offset from the end of the Collection. e.g. * `slice(-2)` returns a Collection of the last two entries. If it is not * provided the new Collection will begin at the beginning of this Collection. * * If end is negative, it is offset from the end of the Collection. e.g. * `slice(0, -1)` returns a Collection of everything but the last entry. If * it is not provided, the new Collection will continue through the end of * this Collection. * @desczh * 从集合的开始位置到结尾位置(不包括结尾)返回一个新集合, * @example * import { slice } from 'fp-ts/slice' * * assert.deepStrictEqual(slice(1)([1, 2, 3]), [2, 3]) * assert.deepStrictEqual(slice([0,2]), [1, 2]) * * @since 0.5.0 */ slice: (begin: number, end?: number) => (f: Kind) => Kind; } export interface Subset extends SubsetCollectionInput, IndexWriterCollection { /** * Get all but the first element of an list, creating a new list, or `None` if the list is empty * @desczh * 得到除了第一个元素以外的所有元素 * @example * import { tail } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(tail([1, 2, 3]), some([2, 3])) * assert.deepStrictEqual(tail([]), none) * * @since 0.5.0 */ tail(as: Kind): Option>; /** * Get all but the last element of an list, creating a new list, or `None` if the list is empty * @desczh * 得到除了最后一个元素以外的所有元素 * @example * import { head } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(head([1, 2, 3]), some([1, 2])) * assert.deepStrictEqual(head([]), none) * * @since 0.5.0 */ head(as: Kind): Option>; /** * Keep only a number of elements from the start of an list, creating a new list. * `n` must be a natural number * @desczh * 得到从开始位置截取的指定数量的集合 * @example * import { takeLeft } from 'fp-ts/List' * * assert.deepStrictEqual(takeLeft(2)([1, 2, 3]), [1, 2]) * * @since 0.5.0 */ takeLeft(n: number): (as: Kind) => Kind; /** * Keep only a number of elements from the end of an list, creating a new list. * `n` must be a natural number * @desczh * 得到从结尾位置截取的指定数量的集合 * @example * import { takeRight } from 'fp-ts/List' * * assert.deepStrictEqual(takeRight(2)([1, 2, 3, 4, 5]), [4, 5]) * * @since 0.5.0 */ takeRight(n: number): (as: Kind) => Kind; /** * Returns a new Collection of the same type which includes entries from this Collection as long as the predicate returns true. * @desczh * 从开始位置截取集合,截取直到指定条件第一次不为true * @example * import { takeLeftWhile } from 'fp-ts/List' * * assert.deepStrictEqual(takeLeftWhile((n: number) => n % 2 === 0)([2, 4, 3, 6]), [2, 4]) * * @since 0.5.0 */ takeLeftWhile(refinement: Refinement): (as: Kind) => Kind; takeLeftWhile(predicate: Predicate): (as: Kind) => Kind; /** * Returns a new Collection of the same type which includes entries from this Collection as long as the predicate returns false. * @desczh * 从开始位置截取集合,截取直到指定条件第一次为true * @example * import { takeLeftUntil } from 'fp-ts/List' * * assert.deepStrictEqual(takeLeftUntil((n: number) => n % 2 === 1)([2, 4, 3, 6]), [2, 4]) * * @since 0.5.0 */ takeLeftUntil(refinement: Refinement): (as: Kind) => Kind; takeLeftUntil(predicate: Predicate): (as: Kind) => Kind; /** * Split an list into two parts: * 1. the longest initial subarray for which all elements satisfy the specified predicate * 2. the remaining elements * @desczh * 拆分一个集合到两个部分 * 1. 第一部分为takeLeftWhile截取的内容 * 2. 第二部分为剩余的内容 * @example * import { spanLeft } from 'fp-ts/List' * * assert.deepStrictEqual(spanLeft((n: number) => n % 2 === 1)([1, 3, 2, 4, 5]), { init: [1, 3], rest: [2, 4, 5] }) * * @since 0.5.0 */ spanLeft(refinement: Refinement): (as: Kind) => { init: Kind; rest: Kind; }; spanLeft(predicate: Predicate): (as: Kind) => { init: Kind; rest: Kind; }; /** * Skip a number of elements from the start of an list, creating a new list * @desczh * 从开始位置跳过指定数量的子集 * @example * import { skipLeft } from 'fp-ts/List' * * assert.deepStrictEqual(skipLeft(2)([1, 2, 3]), [3]) * * @since 0.5.0 */ skipLeft(n: number): (as: Kind) => Kind; /** * Skip a number of elements from the end of an list, creating a new list * @desczh * 从结尾位置跳过指定数量的子集 * @example * import { skipRight } from 'fp-ts/List' * * assert.deepStrictEqual(skipRight(2)([1, 2, 3, 4, 5]), [1, 2, 3]) * * @since 0.5.0 */ skipRight(n: number): (as: Kind) => Kind; /** * Returns a new Collection of the same type which includes entries starting from when predicate first returns false. * @desczh * 截取takeLeftWhile剩余部分 * @example * import { skipLeftWhile } from 'fp-ts/List' * * assert.deepStrictEqual(skipLeftWhile((n: number) => n % 2 === 1)([1, 3, 2, 4, 5]), [2, 4, 5]) * * @since 0.5.0 */ skipLeftWhile(predicate: Predicate): (as: Kind) => Kind; /** * Returns a new `Collection` of the same type which includes entries starting from when predicate first returns true. * @desczh * 截取takeLeftUntil剩余部分 * @example * import { skipLeftUntil } from 'fp-ts/List' * * assert.deepStrictEqual(skipLeftUntil((n: number) => n % 2 === 0)([1, 3, 2, 4, 5]), [2, 4, 5]) * * @since 0.5.0 */ skipLeftUntil(predicate: Predicate): (as: Kind) => Kind; /** * Returns a new Collection with 0 size and no values in constant time. * @desczh * 清除集合,返回空集合 * @example * import { clear } from 'fp-ts/List' * * assert.deepStrictEqual(clear([1, 2, 3, 4]), [])) * * @since 0.5.0 */ clear: (as: Kind) => Kind; /** * Splits an list into two pieces, the first piece has `n` elements. * @desczh * 在指定的位置拆分集合 * @example * import { splitAt } from 'fp-ts/List' * * assert.deepStrictEqual(splitAt(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4, 5]]) * * @since 0.5.0 */ splitAt(n: number): (as: Kind) => [Kind, Kind]; } export declare function initSubset(option: SubsetCollectionInput & IndexWriterCollection): Subset;