| 2139 | * @since 2.0.0 |
| 2140 | */ |
| 2141 | export const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => { |
| 2142 | const f = args.length === 1 ? args[0] : args[1].bind(args[0]) |
| 2143 | const iterator = f(adapter) |
| 2144 | let state: IteratorResult<any> = iterator.next() |
| 2145 | while (!state.done) { |
| 2146 | const current = Gen.isGenKind(state.value) |
| 2147 | ? state.value.value |
| 2148 | : Gen.yieldWrapGet(state.value) |
| 2149 | if (isNone(current)) { |
| 2150 | return current |
| 2151 | } |
| 2152 | state = iterator.next(current.value as never) |
| 2153 | } |
| 2154 | return some(state.value) |
| 2155 | } |
| 2156 | |
| 2157 | /** |
| 2158 | * Merges two optional values, applying a function if both exist. |