UNPKG

data-collectors

Version:

A collection of composable reduction operations for arbitrary streams of values

11 lines (9 loc) 389 B
import { Collector } from "../collector"; export function first<T> () : Collector<T, { value: T }, T> { return Collector.of( () => ( { value: null } ), ( state, item ) => state.value === null ? state.value = item : void 0, ( stateA, stateB ) => ( { value: stateA.value != null ? stateA.value : stateB.value } ), state => state.value ); }