FuncType - v1.21.0
    Preparing search index...

    Type Alias TracedOption<A>

    A wrapper around Option<A> that emits a TraceEvent to the injected Tracer on every combinator call.

    Structure-preserving ops return TracedOption<B>, carrying the same spanId and incrementing seq. Terminal ops (fold, orElse) emit and return the raw value, exiting the wrapper. unwrap() emits a terminal event too, so a span never ends without one.

    declare const user: Option<{ name: string }>
    const events: TraceEvent[] = []
    const tracer = { emit: (e: TraceEvent) => void events.push(e) }

    TracedOption(user, tracer, "span-1")
    .map(u => u.name.trim(), "trim")
    .filter(n => n.length > 0, "non-empty")
    .orElse("anonymous", "fallback")
    type TracedOption<A> = {
        filter(predicate: (a: A) => boolean, label?: string): TracedOption<A>;
        flatMap<B>(f: (a: A) => Option<B>, label?: string): TracedOption<B>;
        fold<B>(onNone: () => B, onSome: (a: A) => B, label?: string): B;
        map<B>(f: (a: A) => B, label?: string): TracedOption<B>;
        orElse<B>(defaultValue: B, label?: string): A | B;
        unwrap(): Option<A>;
    }

    Type Parameters

    • A
    Index
    • Parameters

      • predicate: (a: A) => boolean
      • Optionallabel: string

      Returns TracedOption<A>

    • Type Parameters

      • B

      Parameters

      • onNone: () => B
      • onSome: (a: A) => B
      • Optionallabel: string

      Returns B

    • Type Parameters

      • B

      Parameters

      • defaultValue: B
      • Optionallabel: string

      Returns A | B