3 ms·
Also to follow up on your link to the documentation of promises in Scala, here is a quote: “To simplify the use of callbacks both syntactically and conceptuall
by smadge 8y ago
Also to follow up on your link to the documentation of promises in Scala, here is a quote:
“To simplify the use of callbacks both syntactically and conceptually, Scala provides combinators such as flatMap, foreach, and filter used to compose futures in a non-blocking way.”
‘flatMap’ is exactly the bind function for the promise monad. It doesn’t have to explicitly implement some monad interface to be a monad, it just is.
- still_grokking 8y agoThat's not 100% correct. Something that implements a "monad interface" (e.g. has pure, map and flatMap methods) doesn't compulsorily have to be a monad. A monad has to obey the monad laws to be one. Scala's Future is not a monad per se: https://stackoverflow.com/questions/27454798/is-future-in-scala-a-monad https://stackoverflow.com/questions/27454798/is-future-in-sc...
- smadge 8y agoI was assuming a pure core of Scala, its true I should have been more explicit. Arbitrary side effects and IO make it impossible to reason algebraically/equationally about your programs.
- throwaway487549 8y agoTo be a Monad you have to implement at least 2 functions >>=, and return, which must follow so called Monadic laws (of proper composition - associativity, etc). flatMap is just a function. One more time - Futures are orthogonal to Monads. They may be viewed as such, but it is not necessary. Having only flatMap is sufficient for a strict language.