Documentation
¶
Overview ¶
package result is an experiment in monadic types. The main type is the Res[T], representing the result of some computation. It is useful to use Res in ion.Seq[Res[T]] sequences, since it can capture and propagate errors during I/O or other non-pure functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply f func(T) -> func(Res[T]) Apply takes a function `f` that takes a value of type T and Apply returns a func that takes a value of type Res[T] and applies `f` to the value of type T contained in the result. If the Res[T] is an error result, the function `f` is not called on it.
func FMap ¶
FMap f func(T) -> func(Res[T]) Res[U] FMap takes a function `f` that takes a value of type T and returns a value of type U. FMap returns a func that takes a value of type Res[T] and applies `f` to the value of type T contained in the result, wrapping the value of type U into a Result.
If the Res[T] is an error result, the function `f` is not called on it, and the Res[T] is converted to Res[U], its error.
func Handle ¶
Handle f func(error) -> func(Res[T]) Res[T] Handle takes a function designed to handle errors and returns a function that will apply that handler function to a Res[T], if the Res[T] is an error result.
func Map ¶
Map s Seq[Res[T]] -> f func(T) U -> Seq[Res[U]] Map is analogous to ion.Map, only it maps a function from T to U over a Seq[Result[T]], returning Seq[Result[U]].
The resulting sequence contains f applied to the elements of type T of the Res[T]s where those Res[T]'s are not errors. Res[T] elements that are errors are converted from Res[T] to Res[U] retaining their errors.
Map(s, f) is equivalent to
ion.Map(s, FMap(f))