Effect CommunityEC
Effect Community7mo ago
2 replies
whatplan

Pattern for Mapping an `Effect<Option<A>>` with `(A) => Effect<B>`

Is there a good pattern for effectfully mapping (A) => Effect<B> the value inside of an Effect<Option<A>>?

import { Effect, Option, pipe } from "effect"

declare const foo: Effect.Effect<Option.Option<string>>
declare function bar(s: string): Effect.Effect<number>

const test = pipe(
  foo,
  Effect.flatten,
  Effect.flatMap(bar),
  Effect.optionFromOptional
)

https://effect.website/play#d9720d2cfe5e

this works but idk
Was this page helpful?