context
Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/context.nix
Module Description
Context manipulation utilities for attribute-based state
Combinators
has
Extracts a named attribute from a context.
A utility function for working with attrset-based contexts. In Nix, any attrset naturally “has” its attributes, so this is simply attribute access.
Type Signature
AttrSet -> String -> Value
Parameters
ctx: An attrset contextname: Name of the attribute to extract
Example
has { x = 42; y = 1; } "x" # => 42
See Also
put- Updates an attribute in contextlift- Uses has/put implicitly for effect lifting
lift
Lifts an effect to work with larger contexts.
An effect requiring type A can run in any context that has an
attribute containing A. This is the standard way to compose effects
that work on different parts of a shared context.
Type Signature
String -> Fx<A, V> -> Fx<Ctx, V>
where Ctx is an attrset containing attribute name: A
Parameters
name: The attribute name in the larger contexte: Effect requiring the inner type
Example
runFx (
provide { num = 10; other = "x"; } (
lift "num"
(pending (n: immediate n (n * 3)))
)
) # => 30
How It Works
Uses contraMap to:
- Extract the named attribute for the inner effect
- Update the named attribute with any state changes
See Also
contraMap- Lower-level context transformationlens.zoomOut- Lens-based version
put
Updates a named attribute in a context.
Returns a new attrset with the specified attribute updated. If the attribute doesn’t exist, it is added.
Type Signature
AttrSet -> String -> Value -> AttrSet
Parameters
ctx: The original context attrsetname: Name of the attribute to updatevalue: New value for the attribute
Example
put { x = 1; } "x" 42 # => { x = 42; }
put { x = 1; } "y" 2 # => { x = 1; y = 2; }
See Also
has- Reads an attribute from contextstate.set- Sets the entire state, not just an attribute
Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/context.nix