Nesting promises is always less clear than it could be.
Consider:
alpha takes a url and returns a promise of an http response.
beta takes a url, calls alpha, and returns the promise of some heavy async calculation of an http response.
Versus in un-nested:
alpha takes a url and returns a promise of an http response.
beta takes a http response and returns a promise of some heavy async calculation of that response
All nesting can be expressed this way. (Convince me otherwise)
This property of monads is why Clojure has a threading macro, Haskell has pointfree, and most ML derivatives have a concept of piping.
E.g. you can define function gamma that is expressed as alpha | beta (Aka beta(alpha(x))) that just takes a url and spits out a single promise of a processed http response, but still isn’t nesting!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nesting conditional logic is not always bad.
Nesting promises is always less clear than it could be.
Consider:
alpha
takes a url and returns a promise of an http response.beta
takes a url, callsalpha
, and returns the promise of some heavy async calculation of an http response.Versus in un-nested:
alpha
takes a url and returns a promise of an http response.beta
takes a http response and returns a promise of some heavy async calculation of that responseAll nesting can be expressed this way. (Convince me otherwise)
This property of monads is why Clojure has a threading macro, Haskell has pointfree, and most ML derivatives have a concept of piping.
E.g. you can define function
gamma
that is expressed asalpha | beta
(Akabeta(alpha(x))
) that just takes a url and spits out a single promise of a processed http response, but still isn’t nesting!