UNPKG

macoolka-collection

Version:

`macoolka-collection` Define Data Collection Interface.

155 lines (154 loc) 5.8 kB
/** * Collection Write Interface * @desczh * 可写入集合接口 * @file * @since 0.2.0 */ import { Kind, URIS } from 'fp-ts/HKT'; import { Option } from 'fp-ts/Option'; import { IndexReaderCollection } from './IndexReaderCollection'; import { WriterCollection } from './WriterCollection'; /** * Collection Write Input Interface * @desczh * 可写入集合输入接口 * @since 0.2.0 */ export interface IndexWriteCollectionInput<URI extends URIS> { /** * Delete the element at the specified index, creating a new collection, or returning `None` if the index is out of bounds * @desczh * 删除一个指定位置的元素,返回删除后的集合 * @example * import { deleteAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(deleteAt(0)([1, 2, 3]), some([2, 3])) * assert.deepStrictEqual(deleteAt(1)([]), none) * * @since 2.0.0 */ _deleteAt: <A>(i: number) => (as: Kind<URI, A>) => Kind<URI, A>; /** * Change the element at the specified index, creating a new collection, or returning `None` if the index is out of bounds * @desczh * 修改一个指定位置的元素,返回修改后的集合 * @example * import { setAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(setAt(1, 1)([1, 2, 3]), some([1, 1, 3])) * assert.deepStrictEqual(setAt(1, 1)([]), none) * * @since 2.0.0 */ _setAt: <A>(i: number, a: A) => (as: Kind<URI, A>) => Kind<URI, A>; /** * Insert an element at the specified index, creating a new list, or returning `None` if the index is out of bounds * @desczh * 插入一个指定位置的元素,返回插入后的集合 * @example * import { insertAt } from 'fp-ts/List' * import { some } from 'fp-ts/Option' * * assert.deepStrictEqual(insertAt(2, 5)([1, 2, 3, 4]), some([1, 2, 5, 3, 4])) * * @since 0.5.0 */ _insertAt<A>(i: number, a: A): (as: Kind<URI, A>) => Kind<URI, A>; } export interface IndexWriterCollection<F extends URIS> extends IndexWriteCollectionInput<F>, WriterCollection<F>, IndexReaderCollection<F> { /** * Delete the element at the specified index, creating a new collection, or returning `None` if the index is out of bounds * @desczh * 删除一个指定位置的元素,返回删除后的集合 * @example * import { deleteAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(deleteAt(0)([1, 2, 3]), some([2, 3])) * assert.deepStrictEqual(deleteAt(1)([]), none) * * @since 2.0.0 */ deleteAt: <A>(i: number) => (as: Kind<F, A>) => Option<Kind<F, A>>; /** * Change the element at the specified index, creating a new collection, or returning `None` if the index is out of bounds * @desczh * 修改一个指定位置的元素,返回修改后的集合 * @example * import { setAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(setAt(1, 1)([1, 2, 3]), some([1, 1, 3])) * assert.deepStrictEqual(setAt(1, 1)([]), none) * * @since 2.0.0 */ setAt: <A>(i: number, a: A) => (as: Kind<F, A>) => Option<Kind<F, A>>; /** * Insert an element at the specified index, creating a new list, or returning `None` if the index is out of bounds * @desczh * 插入一个指定位置的元素,返回插入后的集合 * @example * import { insertAt } from 'fp-ts/List' * import { some } from 'fp-ts/Option' * * assert.deepStrictEqual(insertAt(2, 5)([1, 2, 3, 4]), some([1, 2, 5, 3, 4])) * * @since 0.5.0 */ insertAt<A>(i: number, a: A): (as: Kind<F, A>) => Option<Kind<F, A>>; /** * Change the element at the specified index and current item, creating a new collection, or returning `None` if the index is out of bounds * @desczh * 修改一个指定位置的元素,返回修改后的集合 * @example * import { updateAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(updateAt(1, a=>a+1)([1, 2, 3]), some([1, 3, 3])) * * @since 2.0.0 */ updateAt: <A>(i: number, updater: (a: A) => A) => (as: Kind<F, A>) => Option<Kind<F, A>>; /** * Attaches an element to the front of an `Collection`, creating a new non empty `Collection` * @desczh * 插入一个元素到集合头,返回新集合. * @example * import { cons } from 'fp-ts/Array' * * assert.deepStrictEqual(cons(0)([1, 2, 3]), [0, 1, 2, 3]) * * @since 2.0.0 */ cons: <A>(head: A) => (tail: Kind<F, A>) => Kind<F, A>; /** * Append an element to the end of an `Collection`, creating a new `Collection` * @desczh * 插入一个元素到集合尾部,返回新集合. * @example * import { snoc } from 'fp-ts/Array' * * assert.deepStrictEqual(snoc(4)([1, 2, 3]), [1, 2, 3, 4]) * * @since 2.0.0 */ snoc: <A>(end: A) => (init: Kind<F, A>) => Kind<F, A>; /** * Append an element to the end of an `Collection`, creating a new `Collection` * @alias snoc * @desczh * 插入一个元素到集合尾部,返回新集合.是snoc的别名. * @example * import { push } from 'fp-ts/Array' * * assert.deepStrictEqual(push(4)([1, 2, 3]), [1, 2, 3, 4]) * * @since 2.0.0 */ push: <A>(end: A) => (init: Kind<F, A>) => Kind<F, A>; } export declare function initWriter<F extends URIS>(option: IndexReaderCollection<F> & IndexWriteCollectionInput<F>): IndexWriterCollection<F>;