internal/loop
Module to conveniently run function in loop
Use-case for this are:
- Maintain a state while sharing resources easily
- Run operation forever
- Limit cycles a loop can go through
loop.with(with: #([], 0), run: fn(state) {
let #(is, i) = state
case i < 5 {
True -> {
let i = i + 1
loop.Continue(#(list.prepend(is, i), i))
}
_ -> loop.Break(is)
}
})
This is an altered version of https://hex.pm/packages/cycle
Types
Values
pub fn try_inf(
init state: state,
run f: fn(state) -> Result(state, err),
) -> Result(Nil, err)
pub fn try_with(
init state: state,
run function: fn(state) -> Result(Next(state, result), err),
) -> Result(result, err)
Start a fallible loop, returns a result when the function successfully returns Break or an Error if it fails.