Module Yocaml.Task
Source Task is the main abstraction used to describe an action (a task that produces an effect) associated with dependencies and a DSL for composing tasks together.
TypesA task is a particular type of function, which produces an effect, associated with a set of dependencies. That's why it's a type parameterised by an input and an output.
Building tasksSource val make :
?has_dynamic_dependencies :bool ->
Deps.t ->
('a -> 'b Eff.t ) ->
('a , 'b ) t
make deps eff
Builds a task with a fixed set of dependencies and an action.
Source val from_effect :
?has_dynamic_dependencies :bool ->
('a -> 'b Eff.t ) ->
('a , 'b ) t
from_effect
is make Deps.empty
.
Source val lift : ?has_dynamic_dependencies :bool -> ('a -> 'b ) -> ('a , 'b ) t
lift f
lift the function f
into a task with an empty set of dependencies. Useful for transforming regular functions into tasks.
Task is in fact a Strong Profonctor, and therefore an Arrow, hence the presence of an identity morphism, associated with an empty dependency set.
Composing tasksBuilding a construction pipeline involves composing tasks and merging their set of dependencies.
Source val compose : ('b , 'c ) t -> ('a , 'b ) t -> ('a , 'c ) t
compose t2 t1
merges dependencies from t1
and t2
and produce a new action that sequentially performs t1
following by t2
.
Source val rcompose : ('a , 'b ) t -> ('b , 'c ) t -> ('a , 'c ) t
rcompose t1 t2
merges dependencies from t1
and t2
and produce a new action that sequentially performs t1
following by t2
.
Source val pre_compose : ('b -> 'c ) -> ('a , 'b ) t -> ('a , 'c ) t
pre_compose f t
is compose (lift f) t
. It allows to composition between Task and regular function.
Source val post_compose : ('b , 'c ) t -> ('a -> 'b ) -> ('a , 'c ) t
post_compose t f
is compose t (lift f)
. It allows to composition between Task and regular function.
Source val pre_rcompose : ('a -> 'b ) -> ('b , 'c ) t -> ('a , 'c ) t
pre_recompose f t
is rcompose (lift f) t
It allows to composition between Task and regular function.
Source val post_rcompose : ('a , 'b ) t -> ('b -> 'c ) -> ('a , 'c ) t
post_recompose t f
is rcompose t (lift f)
It allows to composition between Task and regular function.
Profunctors operationSince in t
, 'a
is contravariant and 'b
is covariant, we can imagine its profunctorial nature.
Source val dimap : ('a -> 'b ) -> ('c -> 'd ) -> ('b , 'c ) t -> ('a , 'd ) t
dimap f g t
contramap f
on t
and map g
on t
.
Source val lmap : ('a -> 'b ) -> ('b , 'c ) t -> ('a , 'c ) t
lmap f t
contramap f
on t
.
Source val rmap : ('b -> 'c ) -> ('a , 'b ) t -> ('a , 'c ) t
Choice operationsProfunctors with choice, to act on sum-types (using Either
to describe generic sums).
left t
expand the arrow to act only on the Left
part of the sum.
right t
expand the arrow to act only on the Right
part of the sum.
Split the input between the two argument arrows, re-tagging and merging their outputs.
Split the input between the two argument arrows, merging their outputs.
Strong operationsProfunctors with strength, to act on product-types (using ('a * 'b)
to describe generic products).
Source val first : ('a , 'b ) t -> ('a * 'c , 'b * 'c ) t
first t
expand the arrow to act only on the first part of the product.
Source val second : ('a , 'b ) t -> ('c * 'a , 'c * 'b ) t
second t
expand the arrow to act only on the second part of the product.
Source val uncurry : ('a , 'b -> 'c ) t -> ('a * 'b , 'c ) t
Source val split : ('a , 'b ) t -> ('c , 'd ) t -> ('a * 'c , 'b * 'd ) t
Split the input between the two argument arrows and combine their output.
Source val fan_out : ('a , 'b ) t -> ('a , 'c ) t -> ('a , 'b * 'c ) t
Send the input to both argument arrows and combine their output.
Application operationsImplement function application capabilities using Arrow Apply.
Source val apply : (('a , 'b ) t * 'a , 'b ) t
Application of a task to a given input.
Covariant APIRemoving the contravariant component of the profunctor, we have a covariant component that can be treated as a regular Functor. This makes it possible to have linking operators and to make the API potentially less conflicting.
Just a type alias for reducing signatures verbosity
Regular mapping on a task. Since t
is also a Functor.
Lift a regular value into a task.
Regular apply on a task. Since t
is also an Applicative.
Monoidal product between two applicatives.
replace x e
replace the value of e
by x
.
void e
replace the value of e
by unit
.
select e f
apply f
if e
is Left
. It allow to skip effect using Right
.
branch x f g
if x
is Left
, it performs f
, otherwise it performs g
.
Source val map2 : ('a -> 'b -> 'c ) -> 'a ct -> 'b ct -> 'c ct
Source val map3 : ('a -> 'b -> 'c -> 'd ) -> 'a ct -> 'b ct -> 'c ct -> 'd ct
Source val map4 :
('a -> 'b -> 'c -> 'd -> 'e ) ->
'a ct ->
'b ct ->
'c ct ->
'd ct ->
'e ct
Source val map5 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f ) ->
'a ct ->
'b ct ->
'c ct ->
'd ct ->
'e ct ->
'f ct
Source val map6 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g ) ->
'a ct ->
'b ct ->
'c ct ->
'd ct ->
'e ct ->
'f ct ->
'g ct
Source val map7 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h ) ->
'a ct ->
'b ct ->
'c ct ->
'd ct ->
'e ct ->
'f ct ->
'g ct ->
'h ct
Source val map8 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i ) ->
'a ct ->
'b ct ->
'c ct ->
'd ct ->
'e ct ->
'f ct ->
'g ct ->
'h ct ->
'i ct
Infix operatorsSource val (||>) : 'a -> ('a -> 'b ) -> 'b
Source val (<<<) : ('b , 'c ) t -> ('a , 'b ) t -> ('a , 'c ) t
t2 <<< t1
is compose t2 t1
.
Source val (>>>) : ('a , 'b ) t -> ('b , 'c ) t -> ('a , 'c ) t
t1 >>> t2
is rcompose t1 t2
.
a <+< b
compose b
and a
and concat dynamic dependencies set.
a >+> b
compose a
and b
and concat dynamic dependencies set.
Source val (|<<) : ('b -> 'c ) -> ('a , 'b ) t -> ('a , 'c ) t
f ^<< t1
is pre_compose f t1
.
Source val (<<|) : ('b , 'c ) t -> ('a -> 'b ) -> ('a , 'c ) t
t1 <<| f
is post_compose t1 f
.
f *<< t1
is compose (make Deps.empty f) t1
.
t1 <<* f
is compose t1 (make Deps.empty f)
.
Source val (|>>) : ('a -> 'b ) -> ('b , 'c ) t -> ('a , 'c ) t
f |>> t1
is pre_rcompose f t1
.
Source val (>>|) : ('a , 'b ) t -> ('b -> 'c ) -> ('a , 'c ) t
t1 >>| f
is post_rcompose t1 f
.
f *>> t1
is compose (make Deps.empty f) t1
.
t1 >>* f
is compose t1 (make Deps.empty f)
.
t1 +++ t2
is choose t1 t2
.
t1 ||| t2
is fan_in t1 t2
.
Source val (***) : ('a , 'b ) t -> ('c , 'd ) t -> ('a * 'c , 'b * 'd ) t
t1 *** t2
is split t1 t2
.
Source val (&&&) : ('a , 'b ) t -> ('a , 'c ) t -> ('a , 'b * 'c ) t
t1 &&& t2
is fan_out t1 t2
.
Binding operatorslet+ x = t in f x
is f <$> f
.
let+ x = t1 and+ y = t2 in f x y
is f <$> t1 <*> t2
.
UtilsSource val has_dynamic_dependencies : (_ , _ ) t -> bool
has_dynamic_dependencies t
returns true
if task has dynamic dependencies, false
otherwise.
dependencies_of t
returns the dependencies set of a task.
action_of t
returns the effectful function of a task.
destruct t
returns the triple of a dependencies set and an effectful callback and if the task is associated to dynamic dependencies. destruct
is dependencies_of t, action_of t, has_dynamic_dependencies t
no_dynamic_deps
makes an arrow static (does not attach it to any dynamic dependency set).
Source val drop_first : unit -> ('a * 'b , 'b ) t
drop_first t
discards the first element returned by a task.
Source val drop_second : unit -> ('a * 'b , 'a ) t
drop_second t
discards the second element returned by a task.
Source val empty_body : unit -> ('a , 'a * string) t
An arrow that attach an empty body
const x
is an arrow that discard the previous output to replace-it by k
.
with_dynamic_dependencies dependenices_list
allows to add a set of dynamic dependencies to a task. Even the set of dependencies looks static, it is mostly used for attaching dependencies like folders.
Helpers for dealing with static and dynamic dependenciesThe API can change considerably when processing tasks with or without dynamic dependencies, so we are exposing two modules to simplify this processing.
Utilities for dealing with tasks without dynamic dependencies.
Utilities for dealing with tasks with dynamic dependencies.