fun_land v0.7.3 FunLandic.Either
An implementation of the “Either” monad.
Either is very similar to Maybe, with the difference that instead of returning ‘Maybe.nothing’ on failure,
you can specify what to return on failure at each step, so you know where something failed.
TODO:
- Verify implementation.
- Rename to something less ambigous than ‘Either’?
Summary
Functions
Callback implementation for FunLand.Appliable.apply_with/2
Callback implementation for FunLand.Chainable.chain/2
This is called internally whenever a YourMonad.chain() operation fails
Free implementation wrap Mappable.map for Applicative
A variant of reduce/3 that accepts anything that is Combinable as second argument. This Combinable will determine what the neutral value and the combining operation will be
Callback implementation for FunLand.Reducable.reduce/3
Converts the reducable into a list, by building up a list from all elements, and in the end reversing it
Callback implementation for FunLand.Applicative.wrap/1
Macros
Allows you to write multiple consecutive operations using this monad on new lines. This is called ‘monadic do-notation’
Functions
Callback implementation for FunLand.Appliable.apply_with/2.
Callback implementation for FunLand.Chainable.chain/2.
This is called internally whenever a YourMonad.chain() operation fails.
For most monads, the default behaviour of crashing is great. For some, you might want to override it.
A variant of reduce/3 that accepts anything that is Combinable as second argument. This Combinable will determine what the neutral value and the combining operation will be.
Callback implementation for FunLand.Reducable.reduce/3.
Converts the reducable into a list, by building up a list from all elements, and in the end reversing it.
This is an automatic function implementation, made possible because Elixir.FunLandic.Either
implements the FunLand.Reducable behaviour.
Callback implementation for FunLand.Applicative.wrap/1.
Macros
Allows you to write multiple consecutive operations using this monad on new lines. This is called ‘monadic do-notation’.
For more info, see FunLand.Monad.monadic
Rules:
- Every normal line returns a new instance of the monad.
- You can write
x <- some_expr_returning_a_monad_instanceto bindxto whatever is inside the monad. You can then usexon any subsequent lines. - If you want to use one or multiple statements, use
let something = some_statementorlet something = do ...
The final line is of course expected to also return an instance of the monad.
Use wrap at any time to wrap a value back into a monad if you need.
Inside the monadic context, the module of the monad that was defined is automatically imported.
Any local calls to e.g. wrap, apply, chain or functions you’ve defined yourself in your monad module will thus be called on your module.