Put your function in a loop until the cycle (pun intended) breaks
gleam
at master 35 lines 674 B view raw view rendered
1# cycle 2 3[![Package Version](https://img.shields.io/hexpm/v/cycle)](https://hex.pm/packages/cycle) 4[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/cycle/) 5 6```sh 7gleam add cycle@1 8``` 9```gleam 10import cycle 11 12pub fn main() -> Nil { 13 echo cycle.start(with: #([], 0), run: fn(state) { 14 let #(is, i) = state 15 case i < 5 { 16 True -> { 17 let i = i + 1 18 cycle.continue(#(list.prepend(is, i), i)) 19 } 20 _ -> cycle.stop(is) 21 } 22 }) 23 24 // output: [5, 4, 3, 2, 1] 25} 26``` 27 28Further documentation can be found at <https://hexdocs.pm/cycle>. 29 30## Development 31 32```sh 33gleam run # Run the cycle 34gleam test # Run the tests 35```