pub const BYNK_LIST_SRC: &str = "commons bynk.list {\n\t---\n\tReturns the elements of `xs` in reverse order.\n\t---\n\tfn reverse[A](xs: List[A]) -> List[A] {\n\t\tlet init: List[A] = List.empty()\n\t\txs.fold(init, (acc, x) => acc.prepend(x))\n\t}\n\n\t---\n\tApplies `f` to each element of `xs`, returning the results in the same order.\n\t---\n\tfn map[A, B](xs: List[A], f: A -> B) -> List[B] {\n\t\tlet init: List[B] = List.empty()\n\t\treverse(xs.fold(init, (acc, x) => acc.prepend(f(x))))\n\t}\n\n\t---\n\tReturns the elements of `xs` that satisfy the predicate `p`, in order.\n\t---\n\tfn filter[A](xs: List[A], p: A -> Bool) -> List[A] {\n\t\tlet init: List[A] = List.empty()\n\t\treverse(xs.fold(init, (acc, x) => if p(x) { acc.prepend(x) } else { acc }))\n\t}\n\n\t---\n\tReturns the first element of `xs` satisfying `p`, or `None` if none does.\n\t---\n\tfn find[A](xs: List[A], p: A -> Bool) -> Option[A] {\n\t\tlet init: Option[A] = None\n\t\txs.fold(init, (acc, x) => match acc {\n\t\t\tSome(v) => Some(v),\n\t\t\tNone => if p(x) { Some(x) } else { None },\n\t\t})\n\t}\n\n\t---\n\tTrue if at least one element of `xs` satisfies `p`; false for an empty list.\n\t---\n\tfn any[A](xs: List[A], p: A -> Bool) -> Bool {\n\t\tmatch find(xs, p) {\n\t\t\tSome(v) => true,\n\t\t\tNone => false,\n\t\t}\n\t}\n\n\t---\n\tTrue if every element of `xs` satisfies `p`; true for an empty list.\n\t---\n\tfn all[A](xs: List[A], p: A -> Bool) -> Bool {\n\t\tlet init: Option[A] = None\n\t\tlet failed = xs.fold(init, (acc, x) => match acc {\n\t\t\tSome(v) => Some(v),\n\t\t\tNone => if p(x) { None } else { Some(x) },\n\t\t})\n\t\tmatch failed {\n\t\t\tSome(v) => false,\n\t\t\tNone => true,\n\t\t}\n\t}\n\n\t---\n\tRuns the effectful `f` over each element of `xs` in order, collecting the\n\tresults into a single `Effect` that yields the list of outputs.\n\t---\n\tfn traverse[A, B](xs: List[A], f: A -> Effect[B]) -> Effect[List[B]] {\n\t\tlet init: List[B] = List.empty()\n\t\tlet rev <- xs.foldEff(init, (acc, x) => {\n\t\t\tlet y <- f(x)\n\t\t\tEffect.pure(acc.prepend(y))\n\t\t})\n\t\tEffect.pure(reverse(rev))\n\t}\n}\n";Expand description
bynk.list — combinators over the List kernel (fold, prepend,
length, get, foldEff), written in ordinary Bynk (decision 0034):
the first real consumer of v0.20a generics, lambdas, and effectful
traversal. Order-preserving combinators build with fold + prepend
and a final reverse — O(n) builds, never append (which would be
O(n²) over the array lowering).