|
|
|
|
|
by kazagistar
3507 days ago
|
|
Scala calls the monad bind "flatMap". Java actually implements it for Streams. If you have a `Stream<Deck> decks;` of card decks, and want to get all the cards from all the decks, you might try to do something like `decks.map(deck -> deck.getCards().stream())`, but that will give you the type `Stream<Stream<Deck>>`. That sucks, we just want a single stream, not a stream of streams, so we call the function that flattens at the same time. `decks.flatMap(deck -> deck.getCards().stream())`. Nondeterminism is just a standard use for this construction: given one choice, generate more choices, given that choice, generate more choices, do some computation with the choices, and then return the list of possible final results. |
|