effect-io-ai

Package: effect
Module: Option

Option.reduceCompact

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

Example (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; }

Source

Since v2.0.0