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

and

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

Module Description

Pair context transformation utilities

Combinators

andCollapse

Collapses a paired context where both parts are the same type.

When an effect requires {fst: S, snd: S}, this transforms it to require just S, duplicating the single context to satisfy both sides.

Type Signature

Fx<{fst: S, snd: S}, V> -> Fx<S, V>

Parameters

  • e: Effect requiring paired same-type context

Example

runFx (
  provide 10 (
    andCollapse (
      pending (p: immediate p (p.fst + p.snd))
    )
  )
)  # => 20 (10 + 10)

See Also

  • andNil - Extends with unit instead
  • andSwap - Swaps pair components

andNil

Extends an effect’s context with unit on the right.

Transforms an effect requiring S to one requiring {fst: S, snd: {}}. This is useful for uniformity when combining with effects that use paired contexts.

Type Signature

Fx<S, V> -> Fx<{fst: S, snd: {}}, V>

Parameters

  • e: Effect to extend

Example

runFx (
  provide { fst = 10; snd = {}; } (
    andNil (pending (n: immediate n (n * 2)))
  )
)  # => 20

See Also

  • andCollapse - Opposite direction (merges same-type pairs)
  • flatMap - Creates paired context requirements

andSwap

Swaps the components of a paired context requirement.

Transforms an effect requiring {fst: A, snd: B} to one requiring {fst: B, snd: A}. Useful for reordering context structure.

Type Signature

Fx<{fst: A, snd: B}, V> -> Fx<{fst: B, snd: A}, V>

Parameters

  • e: Effect requiring paired context

Example

runFx (
  provide { fst = "hello"; snd = 10; } (
    andSwap (
      pending (p: immediate p p.fst)
    )
  )
)  # => 10 (was in snd, now accessed as fst)

See Also

  • pair.swap - Underlying pair operation
  • andCollapse - Merges same-type pairs

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