Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

state

Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/state.nix

Module Description

Built-in state effect providing get/set/modify operations.

The state effect is a fundamental capability that allows reading and writing to a mutable state. In NFX, state is managed through the context mechanism - the state IS the context.

Namespace Contents

  • get - Reads the current state
  • set - Replaces the state with a new value
  • modify - Transforms state with a pure function
  • modifyM - Transforms state with an effectful function

Example

provide 10 (
  mapM (old:
    then' (state.get)
          (state.modify (x: x + 1))
  ) state.get
)  # State goes 10 -> 11, returns 11

See Also

  • func - Alternative for read-only state access
  • context - For named attribute-based state

Combinators


Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/state.nix