|
|
|
|
|
by Tarean
741 days ago
|
|
Lambdas have two hidden features: Variable capture lets you access variables/values from outer scopes, and statements/calling other functions lets you do control flow. Monads are types that let you build chains of lambdas, so you can mix control flow and variable scoping with the some type-specific logic. Async IO/streams/optionals are monads. It's no accident that these could be programmed as nested callbacks/nested loops/nested if statements. That's the nested chain of Monad->lambda->Monad->... Monads work well with syntax sugar (think async/await), and some languages like Haskell can abstract over them in neat ways. |
|