Effect CommunityEC
Effect Community3y ago
11 replies
Yuriy

Questioning the Generator Syntax of Effect.gen

I'm a bit puzzled by the generator syntax of Effect.gen
export const program = Effect.gen(function* (_) {
  const a = yield* _(task1)
  const b = yield* _(task2)
  const n1 = yield* _(divide(a, b))
  const n2 = increment(n1)
  return `Result is: ${n2}`
})


won't it be more convenient to check if the passed object has an Symbol.asyncIterator assigned to it ? (e.g. is a generator function), and apply one if it's not.

This way we should be able to emulate arrow generators from proposal-generator-arrow-functions https://github.com/tc39/proposal-generator-arrow-functions

export const program = Effect.gen((_) => {
  const a = yield* _(task1)
  const b = yield* _(task2)
  ...
})


Thoughts ?
Was this page helpful?