arrow
Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/arrow.nix
Module Description
Arrow utilities for pure function capabilities.
Arrows are simpler than abilities - they are pure functions that can
be stored in context and requested by name. Unlike abilities which
return effects, arrows are just A -> B functions.
Namespace Contents
new- Creates an arrow from a pure functionrequest- Requests an arrow by name and applies itadapt- Transforms an arrow with pre/post functions
Difference from Abilities
- Ability:
Input -> Fx<S, Output>(effectful) - Arrow:
Input -> Output(pure)
Example
runFx (
provide { double = x: x * 2; }
(arrow.request "double" 21)
) # => 42
See Also
request- For effectful abilitiesfunc- For state-dependent pure functions
Combinators
adapt
Transforms an arrow with pre/post processing functions.
Wraps an arrow with preprocessing (contramap) and postprocessing (map) functions, creating a new arrow with adapted types.
Type Signature
(A' -> A) -> (B -> B') -> Arrow A B -> Arrow A' B'
Parameters
cmap: Preprocess input (A’ -> A)fmap: Postprocess output (B -> B’)f: Original arrowi: Input value
Example
let inc = x: x + 1;
adapted = arrow.adapt (x: x * 2) (x: x * 10) inc;
in adapted 5 # => (5 * 2 + 1) * 10 = 110
See Also
map- Transform effect outputscontraMap- Transform effect inputs
new
Creates an arrow from a pure function.
Arrows are pure functions (A -> B) that can be stored in context
and requested by name. Unlike abilities which return effects,
arrows perform simple transformations.
Type Signature
(A -> B) -> Arrow A B
Parameters
f: Pure function to wrap as arrow
Example
let double = arrow.new (x: x * 2);
in double 21 # => 42
# Store in context for later use
provide {double = arrow.new (x: x * 2);} ...
See Also
request- Retrieve arrow from contextadapt- Transform arrows
request
Requests an arrow by name from context and applies it.
Retrieves a stored arrow function from the context and applies it to an input value, returning the result wrapped in an effect.
Type Signature
String -> A -> Fx<{name: Arrow A B}, B>
Parameters
name: Name of arrow in contexti: Input value
Example
runFx (
provide {double = arrow.new (x: x * 2);} (
arrow.request "double" 21
)
) # => 42
See Also
new- Create arrowsrequest.request- Request abilities (returns effects)
Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/arrow.nix