FunLand.Builtin.SuccessTuple (fun_land v0.10.0)
Uses {:ok, value} | :error | {:error, error}
as representation
of the Either
type:
- Errors are propagated.
Link to this section Summary
Functions
Callback implementation for FunLand.Appliable.apply_with/2
.
Callback implementation for FunLand.Chainable.chain/2
.
Combinable only works if the type inside the success tuples is Combinable.
Callback implementation for FunLand.Combinable.empty/0
.
This is called internally whenever a YourMonad.chain()
operation fails.
Free implementation new Mappable.map as FunLand.Builtin.SuccessTuple is Applicative
Allows you to write multiple consecutive operations using this monad on new lines. This is called 'monadic do-notation'.
Callback implementation for FunLand.Applicative.new/1
.
A variant of reduce that accepts anything that is Combinable as second argument. This Combinable will determine what the empty value and the combining operation will be.
Callback implementation for FunLand.Reducible.reduce/3
.
Converts the reducible into a list, by building up a list from all elements, and in the end reversing it.
Link to this section Functions
apply_discard_left(a, b)
apply_discard_right(a, b)
apply_with(left, right)
Callback implementation for FunLand.Appliable.apply_with/2
.
chain(error_tuple, fun)
Callback implementation for FunLand.Chainable.chain/2
.
combine(left, right)
Combinable only works if the type inside the success tuples is Combinable.
empty()
Callback implementation for FunLand.Combinable.empty/0
.
err?(arg1)
fail(var, expr)
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.
map(a, function)
Free implementation new Mappable.map as FunLand.Builtin.SuccessTuple is Applicative
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_instance
to bindx
to whatever is inside the monad. You can then usex
on any subsequent lines. - If you want to use one or multiple normal statements, use
let something = some_statement
orlet something = do ...
The final line is of course expected to also return an instance of the monad.
Use new
at any time to new 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. new
, apply
, chain
or functions you've defined yourself in your monad module will thus be called on your module.
new(val)
Callback implementation for FunLand.Applicative.new/1
.
ok?(arg1)
reduce(a, combinable)
A variant of reduce that accepts anything that is Combinable as second argument. This Combinable will determine what the empty value and the combining operation will be.
Pass in the combinable module name to start with empty
as accumulator,
or the combinable as struct to use that as starting accumulator.
This is an automatic function implementation, made possible because FunLand.Builtin.SuccessTuple
implements the FunLand.Reducible
behaviour.
See FunLand.Reducible.reduce/2
for examples.
reduce(arg1, acc, fun)
Callback implementation for FunLand.Reducible.reduce/3
.
to_list(reducible)
Converts the reducible 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 FunLand.Builtin.SuccessTuple
implements the FunLand.Reducible
behaviour.