def fact_go

bend-collections@1.0.0.0 · src/math/generic.bend:444

import bend-collections@1.0.0.0/src/math/generic.bend as Generic
import Base
import bend-collections@1.0.0.0/src/math/num.bend as N

444# 2 * 3 * ... * n: i runs up to n, stopping at the first overflow
445def fact_go(~T: Data, ~op: N.Op<T> -> T, ~test: N.Test<T> -> Bool, fuel: Nat, +i: T, +n: T, st: T & Bool, more: Bool) -> Maybe<&2, T>:
446  match fuel st more:
447    case 0n _ _:
448      None{}
449    case 1n+f Tuple{a, False{}} _:
450      None{}
451    case 1n+f Tuple{+a, True{}} False{}:
452      Some{a}
453    case 1n+f Tuple{+a, True{}} True{}:
454      fact_go(~T, ~op, ~test, f, inc(~T, ~op, i), n, mul_by(~T, ~op, ~test, inc(~T, ~op, i), (a, True{})), test(N.Lt{inc(~T, ~op, i), n}))

Uses (9)

Used by (1)