Realm v0.1.0 Realm.Arrow protocol View Source

Arrows abstract the idea of computations, potentially with a context. Arrows are in fact an abstraction above monads, and can be used both to express all other type classes in Realm. They also enable some nice flow-based reasoning about computation. For a nice illustrated explination, see Haskell/Understanding arrows Arrows let you think diagrammatically, and is a powerful way of thinking about flow programming, concurrency, and more.

             ---> f --------------------------
             |                                 v
input ---> split                            unsplit ---> result
             |                                 ^
             |              --- h ---        |
             |              |         v        |
             ---> g ---> split     unsplit ---
                            |         ^
                            --- i ---

Type Class

An instance of Realm.Arrow must also implement Realm.Category, and define Realm.Arrow.arrowize/2.

Semigroupoid  [compose/2, apply/2]
    
 Category     [identity/1]
    
  Arrow       [arrowize/2]

Link to this section Summary

Functions

Lift a function into an arrow, much like how of/2 does with data. Essentially a label for composing functions end-to-end, where instances may have their own special idea of what composition means. The simplest example is a regular function. Others are possible, such as Kleisli arrows.

Link to this section Types

Link to this section Functions

Link to this function

arrowize(sample, fun)

View Source
arrowize(t(), (... -> any())) :: t()

Lift a function into an arrow, much like how of/2 does with data. Essentially a label for composing functions end-to-end, where instances may have their own special idea of what composition means. The simplest example is a regular function. Others are possible, such as Kleisli arrows.

Examples

iex> use Realm.Arrow
...> times_ten = arrowize(fn -> nil end, &(&1 * 10))
...> 5 |> Realm.pipe(times_ten)
50