def run_then
import stelliferous@0.0.2.0/traversal_loop.bend as TraversalLoopimport Base
10# The same loop handing its final state to finish in the base case. A caller
11# that stores its accumulators in finish keeps them out of the loop's return
12# value, so an outlined loop never passes accumulators back by value.
13def run_then(~State: Type,~Result: Type,~step: State -> State,~finish: State -> Result,count: Nat,state: State) -> Result:
14 match count:
15 case 0n: finish(state)
16 case 1n+rest: run_then(~State,~Result,~step,~finish,rest,step(state))