Railway oriented programming in Kotlin

Click for: original source

Railway Oriented Programming (ROP) is a functional programming technique that allows sequential execution of functions, not necessarily synchronous. The key concept is that each function can only accept and return Container of either Success or Failure. Failure wraps Throwable type and Success can be of any type. Published by Tonje Krosby.

This concept is present but not promoted in Kotlin since Kotlin 1.3. The matter of fact Kotlin KEEP states that feature may change in the future. At the time of writing this blog post, Result is a Container-like type which can be used inside generic containers such as Collection.

Example of functions that can have this paradigm and how to write adapters to those functions:

Excellent read for all fans of functional programming!

[Read More]

Tags java functional-programming programming