@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
37 lines (36 loc) • 1.39 kB
TypeScript
import { ResolveCallback, ErrorCallback, ContextType } from '../shared/types';
import { Pipe } from './pipe';
export declare type ReduceFuncSync = (acc: any, cur: any) => any;
export declare type ReduceFuncAsync = (acc: any, cur: any, callback: ResolveCallback<any>, error: ErrorCallback, emissionContext: ContextType, accContext: ContextType) => void;
export declare type ReduceFunc = ReduceFuncSync | ReduceFuncAsync;
/**
*
* Represents [reduce](https://connective.dev/docs/reduce) pins.
*
*/
export declare class Reduce extends Pipe {
readonly reduce: ReduceFunc;
readonly start: any;
private _acc;
/**
*
* @param reduce is the reduction function
* @param start is the start value
*
*/
constructor(reduce: ReduceFunc, start?: any);
private _init;
}
/**
*
* Creates a [reduce](https://connective.dev/docs/reduce) pin.
* A reduce pin can be used to aggregate values over multiple emissions, with an
* aggregator function updating the aggregate value based on each incoming emission.
* [Checkout the docs](https://connective.dev/docs/reduce) for examples and further information.
*
* @param reduce the reduction function
* @param start the start value. If not provided, the value of first incoming emission will be used.
*
*/
export declare function reduce(reduce: ReduceFunc, start?: any): Reduce;
export default reduce;