Applies the effectful function with the specified value, returning the
output in IO
.
Returns a new effectful function that zips together the output of two effectful functions that share the same input.
A symbolic operator for compose
.
A symbolic operator for andThen
.
"Backwards" composition of effectful functions.
Maps the output of this effectful function to the specified constant.
Returns a new effectful function that merely applies this one for its effect, returning the input unmodified.
Composes two effectful functions.
Returns a new effectful function that computes the value of this function, storing it into the first element of a tuple, carrying along the input on the second element of a tuple.
Binds on the output of this effectful function.
Returns a new effectful function that can either compute the value of this
effectful function (if passed Left(a)
), or can carry along any other
C
value (if passed Right(c)
).
Maps the output of this effectful function by the specified function.
Returns a new effectful function that can either compute the value of this
effectful function (if passed Right(a)
), or can carry along any other
C
value (if passed Left(c)
).
Returns a new effectful function that computes the value of this function, storing it into the second element of a tuple, carrying along the input on the first element of a tuple.
Maps the output of this effectful function to Unit
.
Zips the output of this function with the output of that function, using the specified combiner function.
Returns a new effectful function that will either compute the value of this
effectful function (if passed Left(a)
), or will compute the value of the
specified effectful function (if passed Right(c)
).
(Since version 1.0.0) use as
(Since version 1.0.0) use unit
A
FunctionIO[E, A, B]
is an effectful function fromA
toB
, which might fail with anE
.This is the moral equivalent of
A => IO[E, B]
, and, indeed,FunctionIO
extends this function type, and can be used in the same way.The main advantage to using
FunctionIO
is that it provides you a means of importing an impure functionA => B
intoFunctionIO[E, A, B]
, without actually wrapping the result of the function in anIO
value.This allows the implementation to aggressively fuse operations on impure functions, which in turn can result in significantly higher-performance and far less heap utilization than equivalent approaches modeled with
IO
.The implementation allows you to lift functions from
A => IO[E, B]
into aFunctionIO[E, A, B]
. Such functions cannot be optimized, but will be handled correctly and can work in conjunction with optimized (fused)FunctionIO
.Those interested in learning more about modeling effects with
FunctionIO
are encouraged to read John Hughes paper on the subject: Generalizing Monads to Arrows (www.cse.chalmers.se/~rjmh/Papers/arrows.pdf). The implementation in this file contains many of the same combinators as Hughes implementation.A word of warning: while even very complex code can be expressed in
FunctionIO
, there is a point of diminishing return. If you find yourself using deeply nested tuples to propagate information forward, it may be no faster than usingIO
.Given the following two
FunctionIO
:Then the following two programs are equivalent:
Similarly, the following two programs are equivalent:
In both of these examples, the
FunctionIO
program is faster because it is able to perform fusion of effectful functions.