this is so cool, wonder what’s the different to Rx approach?
AFAIK, Rx is an implementation of Functional Reactive Programming paradigm: that focus on stream processing and asynchronous events.
(Functional Reactive Animation - Functional reactive programming - Wikipedia)
TL;DR: ROP is an optional with the “reason” when the result is nil.
The ROP is a revisitation of classical “Either” (Monad) proposed by Scott Wlaschin (Railway Oriented Programming | F# for fun and profit) and focused on the error handling.
Instead of classical if-the-else pyramid, you can reason on the “happy path” only, pretending that everything works, and if any of your “functions” breaks your computation train change the rail and you know why (looking at the error).
As @clattner said, you can have same behaviour with the optional chaining operator a()?.foo().
Q: what happens when you hit
bad
? does it stop? then what happens if you want to do something special in response tobad
?
When the bad happens, you can take a look at your final result, but the current “then” operator is made to interrupt the computation.