provide.nix
Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/provide.nix
Module Description
Context provision and manipulation
Combinators
func
Creates an effect from a function on state.
This is a convenience combinator that reads the state and applies
a pure function to produce the value. Equivalent to map f state.get.
Type Signature
(S -> V) -> Fx<S, V>
Parameters
f: A pure function from state to value
Example
provide 10 (func (n: n * 2)) # => 20
provide { x = 5; } (func (ctx: ctx.x + 1)) # => 6
See Also
state.get- Just reads state without transformationmap- Transforms value of an existing effect
provide
Satisfies a context requirement, eliminating it.
This is the primary way to “run” effects - by providing the context they need. The provided value becomes the context for the inner effect, and the resulting effect has no requirements for that context.
Type Signature
S -> Fx<S, V> -> Fx<T, V> (for any T)
Parameters
s: The context value to providee: Effect that requires contextS
Example
# Effect needing a number
double = pending (n: immediate n (n * 2))
# Provide the number to get a runnable effect
runFx (provide 21 double) # => 42
# Provide a record context
runFx (provide { x = 5; y = 3; }
(pending (ctx: immediate ctx (ctx.x + ctx.y)))) # => 8
See Also
provideLeft- Provides left side of paired contextprovidePart- Provides part using custom getter/setter
provideLeft
Provides the left component of a paired context requirement.
When an effect requires {fst: A, snd: B}, this provides the A
part, leaving an effect that only requires B.
Type Signature
A -> Fx<{fst: A, snd: B}, V> -> Fx<B, V>
Parameters
a: Value for the left/first context componente: Effect requiring paired context
Example
provide 20 (
provideLeft 10
(pending (ctx: immediate ctx (ctx.fst + ctx.snd)))
) # => 30
See Also
provide- Provides entire contextandNil- Extends context given unit on right
providePart
Provides part of a context using custom getter/setter.
A generalized version of provide that allows partial satisfaction
of context requirements using custom lensing functions.
Type Signature
A -> (A -> B -> S) -> (B -> S -> B) -> Fx<S, V> -> Fx<B, V>
Parameters
a: Value to inject into contextcmap: CombinesAand remaining contextBto form full contextSfmap: Extracts remaining context from result statee: Effect requiring full contextS
Example
provide 5 (
providePart 10
(a: b: { x = a; y = b; })
(_b: ctx: ctx.y)
(pending (ctx: immediate ctx (ctx.x + ctx.y)))
) # => 15
See Also
provide- Simpler full context provisionprovideLeft- Standard paired context provision
Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/provide.nix