Effect CommunityEC
Effect Communityβ€’3y agoβ€’
3 replies
virgule

Simplifying Effect Application on Array Elements

Hey πŸ‘‹
i'm trying to apply an effect on each element of an array in a pipeline, but i'm not sure what would be the simplest way to do it.
for instance :
const multiply = (x: number, y: number) => Effect.succeed(x * y);

const program = pipe(
  Effect.succeed([2, 3]),
  Effect.flatMap(numbers =>
    Effect.all(numbers.map(number => multiply(number, 2))),
  ),
);

can i simplify the Effect.flatMap ? seems a bit verbose with the .map, Effect.all, and Effect.flatMap. i'm sure there's a better way but i can't find it.
thanks!
Was this page helpful?