| 782 | * @since 2.0.0 |
| 783 | */ |
| 784 | export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => { |
| 785 | const f = args.length === 1 ? args[0] : args[1].bind(args[0]) |
| 786 | const iterator = f(adapter) |
| 787 | let state: IteratorResult<any> = iterator.next() |
| 788 | while (!state.done) { |
| 789 | const current = Gen.isGenKind(state.value) |
| 790 | ? state.value.value |
| 791 | : Gen.yieldWrapGet(state.value) |
| 792 | if (isLeft(current)) { |
| 793 | return current |
| 794 | } |
| 795 | state = iterator.next(current.right as never) |
| 796 | } |
| 797 | return right(state.value) as any |
| 798 | } |
| 799 | |
| 800 | // ------------------------------------------------------------------------------------- |
| 801 | // do notation |