def wfold

bend-kit-hash@0.3.0.2 · hash.bend:72

import bend-kit-hash@0.3.0.2/hash.bend as Hash
import Base

72# Folds f over n words from word i on. r holds the array and word i.
73def wfold(~T: Type, ~f: T -> @+c: U32 -> T, n: Nat, r: Array<U32> & U32, +i: U32, acc: T) -> Array<U32> & T:
74  match n:
75    case 0n:
76      (a, w) = r
77      (a, acc)
78    case 1n+p:
79      (a, +w) = r
80      +j = (i + 1 : U32)
81      wfold(~T, ~f, p, Array.get(U32, a, j), j, f(acc, w))

Uses (7)

Used by (1)