def group_res_go

bend-prot@0.1.0.0 · pdb.bend:374

import bend-prot@0.1.0.0/pdb.bend as Pdb
import Base
import bend-prot@0.1.0.0/protein.bend as P

374# Pass 1: consecutive equal (chain, seq) merge. Chains and residues run in
375# parallel Data lists: a pair accumulator would not be reusable (+ needs
376# Data), so the two stay aligned and are zipped after (zip_chains).
377# Branchless: both next-states are built as data and picked, with one
378# self-call on the tail, so no helper cycle is needed.
379def group_res_go(items: List<&1, U32 & Nat & P.Atom>, +cur_c: U32, +cur_s: Nat, +cur_as: List<&2, P.Atom>, +acc_c: List<&2, U32>, +acc_r: List<&2, P.Residue>) -> List<&2, U32> & List<&2, P.Residue>:
380  match items:
381    case Nil{}:
382      (List.reverse(&2, U32, cur_c <> acc_c), List.reverse(&2, P.Residue, P.Residue{cur_s, List.reverse(&2, P.Atom, cur_as)} <> acc_r))
383    case (c, s, a) <> t:
384      +c2 = c
385      +s2 = s
386      +same = Bool.and(U32.is_eq(c2, cur_c), Nat.is_eq(s2, cur_s))
387      group_res_go(t, Bool.pick(U32, same, cur_c, c2), Bool.pick(Nat, same, cur_s, s2), a <> Bool.pick(List<&2, P.Atom>, same, cur_as, Nil{}), Bool.pick(List<&2, U32>, same, acc_c, cur_c <> acc_c), Bool.pick(List<&2, P.Residue>, same, acc_r, P.Residue{cur_s, List.reverse(&2, P.Atom, cur_as)} <> acc_r))

Uses (12)

Used by (1)