def insert_by
import bend-mathlib@0.8.1.0/perm.bend as Permimport Base
67# Insertion into a list, generic comparator (structural, Base-only branching via Bool.pick).
68def insert_by(~A: Data, ~le: A -> A -> Bool, +x: A, xs: List<&2, A>) -> List<&2, A>:
69 match xs:
70 case Nil{}:
71 x <> Nil{}
72 case +y <> +t:
73 Bool.pick(List<&2, A>, le(x, y), x <> y <> t, y <> insert_by(~A, ~le, x, t))