| 1488 | * @since 2.0.0 |
| 1489 | */ |
| 1490 | export const gen: Gen.Gen<ResultTypeLambda> = (...args) => { |
| 1491 | const f = args.length === 1 ? args[0] : args[1].bind(args[0]) |
| 1492 | const iterator = f() |
| 1493 | let state: IteratorResult<any> = iterator.next() |
| 1494 | while (!state.done) { |
| 1495 | const current = state.value |
| 1496 | if (isFailure(current)) { |
| 1497 | return current |
| 1498 | } |
| 1499 | state = iterator.next(current.success as never) |
| 1500 | } |
| 1501 | return succeed(state.value) as any |
| 1502 | } |
| 1503 | |
| 1504 | // ------------------------------------------------------------------------------------- |
| 1505 | // do notation |