Hyperlinkv0.8.0-beta.28

Sink

Sink.findEffectconsteffect/Sink.ts:1493
<In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<
  Option.Option<In>,
  In,
  In,
  E,
  R
>

Creates a sink containing the first value matched by an effectful predicate.

When to use

Use when you need to run effects, fail, or use services while searching for the first matching input.

Details

Returns Option.some with the first input whose predicate result is true, or Option.none if the upstream stream ends first. If the predicate effect fails, the sink fails with the same error.

constructorsfind
Source effect/Sink.ts:14938 lines
export const findEffect = <In, E, R>(
  predicate: (input: In) => Effect.Effect<boolean, E, R>
): Sink<Option.Option<In>, In, In, E, R> =>
  reduceWhileEffect(
    Option.none<In>,
    Option.isNone,
    (acc, in_) => Effect.map(predicate(in_), (b) => b ? Option.some(in_) : acc)
  )