FunLand.Chainable behaviour (fun_land v0.10.0)

Defines a 'chain' operation to apply a function that takes a simple value and outputs a new Chainable to a value inside a Chainable.

Something that is Chainable also needs to be Appliable.

Fruit Salad Example

There is one problem we haven't covered yet: What if you have an operation that itself returns a bowl?

Say we have a 'blend' operation, that takes an apple, and returns a bowl with apple juice.

If we would just map 'blend' over a bowl of apples, we would end up putting all the bowls of apple juice inside our original bowl.

This is clearly not what we want. Instead, we want to combine the results together back into a single bowl.

The implementation that tells how to do this, is called chain. For bowls, it would be 'put/pour contents of resulting bowl back into original bowl and forget about the other bowl.'

In Other Environments

  • in Haskell, chain is known by the name bind, or >>=.

Link to this section Summary

Functions

Chains a function that returns a Chainable at the end of some calculation that returns a Chainable.

Link to this section Types

Link to this type

chainable(a)

Specs

chainable(a) :: FunLand.adt(a)

Link to this section Functions

Link to this function

apply_with(a, b)

See FunLand.Appliable.apply_with/2.

Link to this function

chain(chainable, function_that_returns_new_chainable)

Chains a function that returns a Chainable at the end of some calculation that returns a Chainable.

So to chain means: Taking the result of an operation that returns a container outside of its container, and passing it in to the next function, finally returning the resulting container.

See FunLand.Mappable.map/2.

Link to this function

new(module, val)

See FunLand.Applicative.new/2.

Link to this section Callbacks

Link to this callback

chain(chainable, function)

Specs

chain(chainable(a), (a -> b)) :: chainable(b) when a: any(), b: any()