@metreeca/flow - v0.10.0
    Preparing search index...

    Function find

    • Creates a sink retrieving the first matching item of the feed.

      Items are tested in source order and consumption stops at the first match, leaving the rest of the feed unconsumed.

      A feed carrying no matching item resolves to undefined; callers wanting a default supply it with ??, and those requiring a value reach for seek instead.

      Note

      • Incremental: items are drawn only until one matches, so an infinite feed completes unless none does.
      • Streaming: items are tested one at a time, none retained.
      • Stateless: every item is tested on its own.

      Type Parameters

      • V

        The type of items in the feed

      Parameters

      • predicate: (item: NoInfer<V>) => Awaitable<boolean> = ...

        The function testing each item, defaulting to a test matching every item, which retrieves the first item of the feed

      Returns Sink<V, Optional<V>>

      A sink resolving to the first item matching predicate, or to undefined if no item does

      await pipe(
      (items([1, 2, 3, 4, 5]))
      (find(n => n > 3))
      ); // 4

      await pipe(
      (items([1, 2, 3, 4, 5]))
      (find())
      ); // 1