Skuld.Effects.FreshInt (skuld v0.30.0)

View Source

FreshInt effect — generate monotonically increasing integers.

Zero dependencies. The handler stores a seed value in env state, returns it, and increments. Both test and production handlers use the same counter implementation — deterministic by default, no external library needed.

Production Usage

comp do
  id <- FreshInt.fresh_integer()
  id
end
|> FreshInt.with_handler()
|> Comp.run!()
#=> 0

Test Usage (Deterministic)

comp do
  id <- FreshInt.fresh_integer()
  id
end
|> FreshInt.with_handler(seed: 100)
|> Comp.run!()
#=> 100  (deterministic, reproducible)

Summary

Functions

state_key(tag)

with_handler(comp, opts \\ [])

Install a FreshInt handler.

Options

  • :seed — starting integer value (default: 0)