/** * Collection Reader 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 { ConstructorCollection } from './Constructor'; /** * Collection Reader Input Interface * @desczh * 可读集合输入接口 */ export interface ReaderCollectionInput { /** * Returns the size of this `Collection`. * @desczh * 获取集合数据数量 * @example * import { count } from 'fp-ts/Array' * * assert.deepStrictEqual(count([1, 2, 3]), 3) * * @since 0.5.0 */ size: (f: Kind) => number; /** * Return An iterator of this Collection's values. * @desczh * 获取集合迭代器 * @example * import { getiterator } from 'fp-ts/Array' * * const iterator = getiterator(['1','2']) * * @since 0.5.0 */ getiterator: (f: Kind) => Iterable; /** * Reverse an list, creating a new list * @desczh * 翻转一个集合 * @example * import { reverse } from 'fp-ts/List' * * assert.deepStrictEqual(reverse([1, 2, 3]), [3, 2, 1]) * * @since 0.5.0 */ reverse(as: Kind): Kind; } /** * Collection Reader Output Interface * @desczh * 可读集合输出接口 */ export interface ReaderCollection extends ReaderCollectionInput, ConstructorCollection { /** * True if a `Collection` size equal zero * @desczh * 判断集合是否为空 * @example * import { isEmpty } from 'fp-ts/Array' * * assert.deepStrictEqual(isEmpty([1, 2, 3]), false) * assert.deepStrictEqual(isEmpty([1, 2, 3]), true) * * @since 0.5.0 */ isEmpty: (f: Kind) => boolean; /** * False if a `Collection` size equal zero * @desczh * 判断集合是否为非空 * @example * import { notEmpty } from 'fp-ts/Array' * * assert.deepStrictEqual(notEmpty([1, 2, 3]), false) * assert.deepStrictEqual(notEmpty([1, 2, 3]), true) * * @since 0.5.0 */ notEmpty: (f: Kind) => boolean; /** * Get the first element in an list, or `None` if the list is empty * @desczh * 返回第一条记录 * @example * import { first } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(first([1, 2, 3]), some(1)) * assert.deepStrictEqual(first([]), none) * * @since 0.5.0 */ first(as: Kind): Option; /** * Get the last element in an list, or `None` if the list is empty * @desczh * 返回最后一条记录 * @example * import { getLast } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(last([1, 2, 3]), some(3)) * assert.deepStrictEqual(last([]), none) * * @since 0.5.0 */ last(as: Kind): Option; /** * True if a particular condition exists * @desczh * 判断给定的条件是否存在记录 * @example * import { exist } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(exist()([1, 2, 3]), some(1)) * assert.deepStrictEqual(first([]), none) * * @since 0.5.0 */ exist(predicate: Predicate): (f: Kind) => boolean; /** * Find the first element which satisfies a predicate (or a refinement) function * @desczh * 获得第一个满足条件的元素 * @example * import { findFirst } from 'fp-ts/List' * import { some } from 'fp-ts/Option' * * assert.deepStrictEqual(findFirst((x: { a: number, b: number }) => x.a === 1)([{ a: 1, b: 1 }, { a: 1, b: 2 }]), some({ a: 1, b: 1 })) * * @since 0.5.0 */ findFirst(refinement: Refinement): (as: Kind) => Option; findFirst(predicate: Predicate): (f: Kind) => Option; /** * Find the first element returned by an option based selector function * @desczh * 获得第一个满足条件的元素,并转换元素 * @example * import { findFirstMap } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * interface Person { * name: string * age?: number * } * * const persons: List = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }] * * // returns the name of the first person that has an age * assert.deepStrictEqual(findFirstMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Mary')) * * @since 0.5.0 */ findFirstMap(f: (a: A) => Option): (as: Kind) => Option; /** * Find the last element which satisfies a predicate function * @desczh * 获得最后一个满足条件的元素 * @example * import { findLast } from 'fp-ts/List' * import { some } from 'fp-ts/Option' * * assert.deepStrictEqual(findLast((x: { a: number, b: number }) => x.a === 1)([{ a: 1, b: 1 }, { a: 1, b: 2 }]), some({ a: 1, b: 2 })) * * @since 0.5.0 */ findLast(refinement: Refinement): (as: Kind) => Option; findLast(predicate: Predicate): (as: Kind) => Option; /** * Find the last element returned by an option based selector function * @desczh * 获得最后一个满足条件的元素,并转换元素 * @example * import { findLastMap } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * interface Person { * name: string * age?: number * } * * const persons: List = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }] * * // returns the name of the last person that has an age * assert.deepStrictEqual(findLastMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Joey')) * * @since 0.5.0 */ findLastMap(f: (a: A) => Option): (as: Kind) => Option; /** * The sideEffect is executed for every entry in the `Collection`. * * break when function return false * @desczh * 遍历每一个元素 * 函数返回false时,中断遍历 * @example * import { forEach } from 'fp-ts/Array' * * const values=[] * forEach(a=>values.push(a))([1, 2, 3]) * assert.deepStrictEqual(values, [1, 2, 3]) * * @since 0.5.0 */ forEach: (f: Predicate) => (as: Kind) => void; /** * Shallowly converts this `collection` to an Array. * @desczh * 转换集合到数组 * @example * import { toArray } from 'fp-ts/Array' * * const values=[] * assert.deepStrictEqual(toArray([1,2,3]), [1,2,3]) * * @since 0.5.0 */ toArray: (as: Kind) => Array; /** * True if predicate returns true for all entries in the `Collection`. * @desczh * 判断是否所有元素都满足条件 * @example * import { every } from 'fp-ts/Array' * * const values=[] * assert.deepStrictEqual(every(a=>a==1)([1,2,3]), false) * * @since 0.5.0 */ every(predicate: Predicate): (as: Kind) => boolean; /** * True if predicate returns true for any entry in the `Collection`. * @desczh * 判断是否有一个元素都满足条件 * @example * import { some } from 'fp-ts/Array' * * assert.deepStrictEqual(some(a=>a===1)([1,2,3]), true) * * @since 0.5.0 */ some(predicate: Predicate): (as: Kind) => boolean; } export declare function initReaderCollection(options: ReaderCollectionInput & ConstructorCollection): ReaderCollection;