Package: effect
Module: Option
Reduces an iterable of Options to a single value, skipping None entries.
When to use
Use when you need to aggregate values from a collection where some may be absent.
Details
f only to Some valuesNone values are skipped entirelyExample (Summing present values)
import { Option, pipe } from "effect"
const items = [Option.some(1), Option.none(), Option.some(2), Option.none()]
console.log(pipe(items, Option.reduceCompact(0, (b, a) => b + a)))
// Output: 3
Signature
declare const reduceCompact: { <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B; <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B; }
Since v2.0.0