cycle
gleam add cycle@1
import cycle
pub fn main() -> Nil {
echo cycle.start(with: #([], 0), run: fn(state) {
let #(is, i) = state
case i < 5 {
True -> {
let i = i + 1
cycle.continue(#(list.prepend(is, i), i))
}
_ -> cycle.stop(is)
}
})
// output: [5, 4, 3, 2, 1]
}
Further documentation can be found at https://hexdocs.pm/cycle.
Development
gleam run # Run the cycle
gleam test # Run the tests