/** * Collection Reader Interface * @desczh * 可读集合接口 * @file * @since 0.2.0 */ import { Kind, URIS } from 'fp-ts/HKT'; import { Option } from 'fp-ts/Option'; import { Predicate } from 'fp-ts/function'; import { PredicateWithIndex } from 'fp-ts/FilterableWithIndex'; import { ReaderCollectionInput, ReaderCollection } from './ReaderCollection'; /** * Collection Reader Input Interface * @desczh * 可读集合输入接口 */ export interface IndexReaderCollectionInput { /** * This function read a value at a particular index from an `Collection` * @desczh * 用key读取集合数据 * @example * import { getAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(getAt(1)([1, 2, 3]), some(2)) * assert.deepStrictEqual(getAt(3)([1, 2, 3]), none) * * @since 0.5.0 */ _getAt: (i: number) => (f: Kind) => A | undefined | null; } /** * Collection Reader Output Interface * @desczh * 可读集合输出接口 */ export interface IndexReaderCollection extends ReaderCollectionInput, ReaderCollection, IndexReaderCollectionInput { /** * This function read a value at a particular index from an `Collection` * @desczh * 从集合中用key得到记录 * @example * import { getAt } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(getAt(1)([1, 2, 3]), some(2)) * assert.deepStrictEqual(getAt(3)([1, 2, 3]), none) * * @since 0.5.0 */ getAt: (i: number) => (f: Kind) => Option; /** * True if a particular index exists from an `Collection` * @desczh * 判断给定的key是否有对应记录 * @example * import { existAt } from 'fp-ts/Array' * * assert.deepStrictEqual(existAt(1)([1, 2, 3]), true) * assert.deepStrictEqual(existAt(3)([1, 2, 3]), false) * * @since 2.0.0 */ existAt: (i: number) => (f: Kind) => boolean; /** * Find the first index for which a predicate holds * @desczh * 得到第一个满足条件的key * @example * import { findFirstIndex } from 'fp-ts/Array' * import { some, none } from 'fp-ts/Option' * * assert.deepStrictEqual(findFirstIndex((n: number) => n === 2)([1, 2, 3]), some(1)) * assert.deepStrictEqual(findFirstIndex((n: number) => n === 2)([]), none) * * @since 0.5.0 */ findFirstIndex: (predicate: Predicate) => (f: Kind) => Option; /** * Returns the index of the last element of the list which matches the predicate * @desczh * 得到最后一个满足条件的key * @example * import { findLastIndex } from 'fp-ts/List' * import { some, none } from 'fp-ts/Option' * * interface X { * a: number * b: number * } * const xs: List = [{ a: 1, b: 0 }, { a: 1, b: 1 }] * assert.deepStrictEqual(findLastIndex((x: { a: number }) => x.a === 1)(xs), some(1)) * assert.deepStrictEqual(findLastIndex((x: { a: number }) => x.a === 4)(xs), none) * * * @since 0.5.0 */ findLastIndex(predicate: Predicate): (as: Kind) => Option; /** * Returns the index of the element of the list which matches the predicate * @desczh * 得到一个满足条件的key数组 * @example * import { findIndex } from 'fp-ts/List' * * interface X { * a: number * b: number * } * const xs: List = [{ a: 1, b: 0 }, { a: 1, b: 1 }] * assert.deepStrictEqual(findIndex((x: { a: number }) => x.a === 1)(xs), [1]) * assert.deepStrictEqual(findIndex((x: { a: number }) => x.a === 4)(xs), []) * * * @since 0.5.0 */ findIndex(predicate: Predicate): (as: Kind) => number[]; /** * 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 */ forEachIndex: (f: PredicateWithIndex) => (as: Kind) => void; /** * 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 */ everyIndex(predicate: PredicateWithIndex): (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 */ someIndex(predicate: PredicateWithIndex): (as: Kind) => boolean; } export declare function initIndexReaderCollection(options: IndexReaderCollectionInput & ReaderCollection): IndexReaderCollection;