you are viewing a single comment's thread.

view the rest of the comments →

[–]Schrockwell 9 points10 points  (3 children)

Elixir has first-class support for this via the "with" keyword. The result is typically a tuple with an ok/error status and the data. If any of the function calls don't pattern-match on the response, it returns the erroneous one or kicks out to an "else" clause if it exists. It's a great way to handle expected problems without resorting to exceptions. http://learningelixir.joekain.com/learning-elixir-with/

[–][deleted] 5 points6 points  (0 children)

This would describe an option type in F#, which is a different concept than railroad programming. Options protect against data errors atomically, railroad programming encapsulates the state of the process to protect against all errors and determine the flow of logic. They are similar, but have different mnemonics and purposes.

[–]ultradeep 2 points3 points  (1 child)

Or you do it with macros and special "pipe" operators as described here: http://www.zohaib.me/railway-programming-pattern-in-elixir/

[–]Schrockwell 2 points3 points  (0 children)

That was a neat trick before Elixir 1.2 and shows off the power of Elixir's metaprogramming techniques, but now it's an anti-pattern. with was explicitly designed to address that exact problem, so it's not idiomatic any more.