d at domenic.me (2015-07-07T02:08:22.635Z)
Mark S. Miller schrieb:
> Flatmap of generators can approximately be modeled in terms of "`yield*` wrap"
So you have a signature of `Iterable<Generator<i, o, r>> -> Generator<i, o, r>` in mind, not a monadic `join`-like function that takes a generator?
> flatMap([g1, g2]) is equivalent to
Maybe it should be
```js
(function*() {
return [yield* wrap(g1, function.sent), yield* g2];
}())
```
with `Iterable<Generator<i, o, r>> -> Generator<i, o, Iterable<r>>`?
Mark S. Miller schrieb: > Something strange and bizarre that Jafar and I just discovered after the > TC39 meeting: > > We all know that there are a set of conventional combinators, like > flatMap, that work fine for iterators. > > Iterators are uni-directional. Generators are bi-directional. (As Jara > observes: Generator implements Iterator, Observer) > > We thought that these combinators did not apply to generators in their > full bidirectional glory. We were wrong. > > Flatmap of generators can approximately be modeled in terms of "yield* > wrap" So you have a signature of `Iterable<Generator<i, o, r>> -> Generator<i, o, r>` in mind, not a monadic `join`-like function that takes a generator? > flatMap([g1, g2]) is equivalent to > > (function*() { > yield* wrap(g1, function.sent); // result of g1 ignored! > return yield* g2; > }()) Maybe it should be (function*() { return [yield* wrap(g1, function.sent), yield* g2]; }()) with `Iterable<Generator<i, o, r>> -> Generator<i, o, Iterable<r>>`? Bergi