UNPKG

arachnea

Version:

A simple api to perform array operations in a single loop

22 lines (21 loc) 873 B
export type ArrayTransformer<T, K> = (ele: T) => K; export type ReduceTransformer<T, K> = (accumilator: K, currentValue: T) => K; export type Condition<T> = ((ele: T) => boolean) | T; type StreamInterrupt = { interrupted: boolean; }; declare class Stream<T> { private list; private actionStack; constructor(list: Array<T>); map<K>(transformer: ArrayTransformer<T, K>): Stream<K>; forEach(transformer: ArrayTransformer<T, void>): this; filter(transformer: ArrayTransformer<T, boolean>): this; remove(condition: Condition<T>): this; actionLoop<R>(operation: (ele: T) => void, interupt?: StreamInterrupt): void; reduce<K>(transformer: ReduceTransformer<T, K>, initialValue: K): K; find(condition: Condition<T>): T | undefined; collect(): Array<T>; } declare const stream: <T>(arr: Array<T>) => Stream<T>; export default stream;