Effect CommunityEC
Effect Community2y ago
5 replies
Kasper

Refining Syntax of Generator Functions

@Andarist @Michael Arnaldi
I wonder if we could make the syntax of generator function even more close to async/await:

// Current way
const getTodoById = (id: string) =>
  Effect.gen(function* () {
    yield* Console.log('prettier forces a bit weird extra lines and indentation');
    return { description: "Learn effect" };
  });

// But now we don't need adapters anymore, what about ?!?
const getTodoByIdBeautiful = Effect.gen(function* (id: string) {
  // implementation
  yield* Console.log('no extra indentation!');
  return { description: "Learn effect" };
})
// would satisfies (id: string) => Effect.Effect<Todo> (so would be a breaking change)

const getAllTodos = Effect.gen(function* () {
  // implementation
  yield* Console.log('stays the same');
  return [{ description: "Learn effect" }];
})
// would satisfies Effect.Effect<Todo> as it does today
Was this page helpful?