And yet we somehow don't acknowledge the fact that this is just do-notation for some specific monad--yeah, that powerful abstraction that can't be expressed in Rust because we don't allow higher-order polymorphism. Don't get me wrong, i'm bitter because i feel like Rust really is almost in the right direction for the future of language design. Yet there is a long time before we get a language with a really precise ty…
I have been doing programming, including functional programming for more than two decades, I still don't really know what a "monad" is. Each time someone explains it to me, I understand something different.
Future, Option, List, State/IO, etc.
And the do-notation that some comments mention become a long list of flatMap/filter/map invocations.
do {
futRecord record.id)
username = futRecord.map(record -> record.name)
futResult
This is just an abstraction, and it's not exactly a pretty one, but better than the flatMap hell in functional languages.The do-notation uses the same monad throughout, in this example the Future one. The final yield is a map, the "Finally, Monads are very much like Vector Spaces in Maths. You have Axioms for both, and if the object satisfies them, it's a Monad or Vector Space!