19 Matching Annotations
- Mar 2021
-
trailblazer.to trailblazer.to
-
Remember, in a railway activity each task has two standard outputs with the “semantics” success and failure.
-
-
trailblazer.to trailblazer.to
-
The flow pipetree is a mix of the Either monad and “Railway-oriented programming”, but not entirely the same.
-
- Feb 2021
-
trailblazer.to trailblazer.to
-
The DSL will, per default, wrap every task with the Binary interface, meaning returning true will result in Activity::Right, and false in Activity::Left.
-
Note that you can return either a boolean value or a [signal subclass] in order to dictate the direction of flow.
-
-
trailblazer.to trailblazer.to
-
-
Each step receives the return value of its predecessor. The return value decides about what next step is called.
-
the ability to “error out” when something goes wrong
-
Six lines of code create an executable object that, when invoked, will run your code in the order as visible in our diagram, plus the ability to “error out” when something goes wrong.
-
While you could program this little piece of logic and flow yourself using a bunch of Ruby methods along with a considerable amount of ifs and elses, and maybe elsif, if you’re feeling fancy, a Trailblazer activity provides you a simple API for creating such flow without having to write and maintain any control code. It is an abstraction.
-
Modelling the flow of a program where chunks of code are executed in a certain order, with a successful “happy path” and an “error-out” path is called a Railway. It popped up in functional languages
first sighting: railway-oriented programming
-
-
sobolevn.me sobolevn.me
-
Let’s start with the same number dividing example, which returns 0 when the error happens. Maybe instead we can indicate that the result was not successful without any explicit numerical value?
-
Now you can easily spot them! The rule is: if you see a Result it means that this function can throw an exception. And you even know its type in advance.
-
-
www.morozov.is www.morozov.is
-
Railway Oriented Programming is a way to gracefully handle errors in your application
-
However, you don’t need to have an extensive knowledge of monads to use ROP in your code.
-
Railway Oriented Programming comes from functional programming, so it is tightly related to the usual FP concepts like monads, composition, and many others.
-
-
jrsinclair.com jrsinclair.com
-
The .chain() method allows us to switch over to the left track if an error occurs. Note that the switches only go one way.
-
-
fsharpforfunandprofit.com fsharpforfunandprofit.com
-
This is a useful approach to error handling, but please don’t take it to extremes! See my post on “Against Railway-Oriented Programming”.
-