Put your function in a loop until the cycle (pun intended) breaks
gleam
Gleam 79.0%
Nix 20.7%
Shell 0.3%
Other 0.1%
1 1 0

Clone this repository

https://tangled.org/fuzzko.neocities.org/cycle https://tangled.org/did:plc:rz5oaphir5tj5vbo7ji7zvto/cycle
git@tangled.org:fuzzko.neocities.org/cycle git@tangled.org:did:plc:rz5oaphir5tj5vbo7ji7zvto/cycle

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

cycle#

Package Version Hex Docs

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