def split.cut
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytesimport Base
512# r holds the buffer and the piece that ends at end; each earlier cut j starts one at j + m.
513def split.cut(cuts: List<&2, U32>, r: Bytes & Bytes, +end: U32, +m: U32, acc: List<&1, Bytes>) -> List<&1, Bytes>:
514 match cuts:
515 case Nil{}:
516 (b, piece) = r
517 Con{snd(slice(b, 0, end)), Con{piece, acc}}
518 case Con{+j, t}:
519 (b, piece) = r
520 split.cut(t, slice(b, (j + m : U32), (end - j - m : U32)), j, m, Con{piece, acc})