Put your function in a loop until the cycle (pun intended) breaks
gleam
at master 34 lines 651 B view raw
1import cycle 2import gleeunit 3 4pub fn main() { 5 gleeunit.main() 6} 7 8type CycleState { 9 CycleState(xs: List(Int), i: Int) 10} 11 12pub fn cycle_test() { 13 let j = 5 14 let xs = 15 cycle.start(with: CycleState(xs: [], i: 0), run: fn(state) { 16 case state.i < j { 17 True -> { 18 let i = state.i + 1 19 let xs = [i, ..state.xs] 20 cycle.continue(CycleState(xs:, i:)) 21 } 22 _ -> cycle.stop(state.xs) 23 } 24 }) 25 assert xs == [5, 4, 3, 2, 1] 26} 27 28pub fn max_cycle_test() { 29 let result = 30 cycle.safely_start(with: Nil, max_cycle: 1000, run: fn(_) { 31 cycle.continue(Nil) 32 }) 33 assert result == Error(Nil) 34}