Visit each byte exactly once in increasing offset order. The consumer is
pure and may be non-associative. Empty input returns the initial state.
Count the input once; exactly that many head/tail steps cannot overrun it.
Storage retained by the consumer is its own contract. The traversal itself
retains one suffix and one accumulator, rather than a per-byte closure chain.
18def bytesFoldFromStart =
19 (lambda erased state : Type 0 .
20 unrestricted consume : (pi unrestricted offset : Nat . unrestricted value : Byte . unrestricted accumulated : state . state) .
21 unrestricted initial : state .
22 unrestricted input : Bytes .
23 eliminate
24 BytesTraversalState
25 (lambda unrestricted cursor : (family BytesTraversalState state) . state)
26 (nat-eliminate
27 (lambda unrestricted count : Nat . family BytesTraversalState state)
28 (constructor BytesTraversalState BytesTraversalStateValue state input initial)
29 (lambda unrestricted offset : Nat .
30 unrestricted previous : (family BytesTraversalState state) .
31 eliminate
32 BytesTraversalState
33 (lambda unrestricted cursor : (family BytesTraversalState state) .
34 family BytesTraversalState state)
35 previous
36 (branch BytesTraversalStateValue remaining accumulated .
37 constructor
38 BytesTraversalState
39 BytesTraversalStateValue
40 state
41 (bytes-tail remaining)
42 (consume offset (bytes-head remaining) accumulated)))
43 (bytes-length input))
44 (branch BytesTraversalStateValue remaining accumulated . accumulated))The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.