Handling Iterables with Effect.gen/yield* and Effect.all in Typescript

I'm having a tough time understanding how to deal with the Effect.gen/yield* pattern when dealing with iterables. for the most part it makes sense as a drop in mental model for async/await, but what if I need to map an array of strings to an array of Effects

do i just need to use Effect.all (similarly to how i'd need Promise.all?

is there a better way to approach this?

export const createUsers = Effect.fn("createUsers")(function* () {
  const myHandle = String.split(yield* UserEmail, "@").at(0) as string;
  const toInsert = Array.prepend(mock.users, myHandle);

  const insertables = toInsert.map(createInsert); // string[]

  const created = yield* Effect.all(
    insertables.map((insert) => users.create(insert)), // users.create returns Effect<string[], ..., ...>
  );

  return created;
});
Was this page helpful?