<A>(reducer: Reducer.Reducer<A>): Reducer.Reducer<A | undefined>Creates a Reducer for A | undefined by wrapping an existing reducer with
fail-fast semantics.
When to use
Use to wrap an existing Reducer so any undefined value aborts the entire
reduction result.
Details
- Initial value is the wrapped reducer's
initialValue - Combining two defined values delegates to the wrapped reducer
- If the accumulator or next value is
undefined, the reduction returnsundefined
constructorsmakeCombinerFailFast
Source effect/UndefinedOr.ts:22812 lines
export function function makeReducerFailFast<A>(
reducer: Reducer.Reducer<A>
): Reducer.Reducer<A | undefined>
Creates a Reducer for A | undefined by wrapping an existing reducer with
fail-fast semantics.
When to use
Use to wrap an existing Reducer so any undefined value aborts the entire
reduction result.
Details
- Initial value is the wrapped reducer's
initialValue
- Combining two defined values delegates to the wrapped reducer
- If the accumulator or next value is
undefined, the reduction returns undefined
makeReducerFailFast<function (type parameter) A in makeReducerFailFast<A>(reducer: Reducer.Reducer<A>): Reducer.Reducer<A | undefined>A>(reducer: Reducer.Reducer<A>(parameter) reducer: {
initialValue: A;
combineAll: (collection: Iterable<A>) => A;
combine: (self: A, that: A) => A;
}
reducer: import ReducerReducer.type Reducer.Reducer = /*unresolved*/ anyReducer<function (type parameter) A in makeReducerFailFast<A>(reducer: Reducer.Reducer<A>): Reducer.Reducer<A | undefined>A>): import ReducerReducer.type Reducer.Reducer = /*unresolved*/ anyReducer<function (type parameter) A in makeReducerFailFast<A>(reducer: Reducer.Reducer<A>): Reducer.Reducer<A | undefined>A | undefined> {
const const combine: anycombine = function makeCombinerFailFast<A>(
combiner: Combiner.Combiner<A>
): Combiner.Combiner<A | undefined>
Creates a Combiner for A | undefined that combines values only when both
operands are defined.
When to use
Use to lift a Combiner so any undefined operand makes the combined result
undefined.
Details
undefined combined with any value returns undefined
- Any value combined with
undefined returns undefined
a combined with b returns combiner.combine(a, b)
makeCombinerFailFast(reducer: Reducer.Reducer<A>(parameter) reducer: {
initialValue: A;
combineAll: (collection: Iterable<A>) => A;
combine: (self: A, that: A) => A;
}
reducer).combine
const const initialValue: A | undefinedinitialValue = reducer: Reducer.Reducer<A>(parameter) reducer: {
initialValue: A;
combineAll: (collection: Iterable<A>) => A;
combine: (self: A, that: A) => A;
}
reducer.initialValue as function (type parameter) A in makeReducerFailFast<A>(reducer: Reducer.Reducer<A>): Reducer.Reducer<A | undefined>A | undefined
return import ReducerReducer.make(const combine: anycombine, const initialValue: A | undefinedinitialValue, (collection: anycollection) => {
let let out: A | undefinedout = const initialValue: A | undefinedinitialValue
for (const const value: anyvalue of collection: anycollection) {
let out: A | undefinedout = const combine: anycombine(let out: A | undefinedout, const value: anyvalue)
if (let out: A | undefinedout === var undefinedundefined) return let out: A | undefinedout
}
return let out: A | undefinedout
})
}