~/bend-docscommunity

shared/lists.bend checks

raw source on the hub · import bend-lint-api@0.1.0.0/shared/lists.bend as Lists

List helpers. They recurse only in tail position, so a long list is fine on the JS lane, whose stack is small; Base's append, concat, length, any and sort recurse on the stack.

1 import
import Base

Definitions

def when source · line 5 · raw

@-A:Data -> @hit:Bool -> @v:A -> Maybe<&2, A>

def onto source · line 13 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @out:List<a, A> -> List<a, A>

xs, last first, onto out.

def append source · line 20 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @ys:List<a, A> -> List<a, A>

def concat.go source · line 23 · raw

@-a:Quant -> @-A:Kind(a) -> @xss:List<a, List<a, A>> -> @out:List<a, A> -> List<a, A>

def concat source · line 30 · raw

@-a:Quant -> @-A:Kind(a) -> @xss:List<a, List<a, A>> -> List<a, A>

def length.go source · line 33 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @n:Nat -> Nat

def length source · line 40 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> Nat

def push source · line 56 · raw

@-A:Data -> @x:Maybe<&2, A> -> @out:List<&2, A> -> List<&2, A>

def sort.runs source · line 63 · raw

@-A:Data -> @xs:List<&2, A> -> @out:List<&2, List<&2, A>> -> List<&2, List<&2, A>>

def deal.go source · line 110 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @even:Bool -> @l:List<a, A> -> @r:List<a, A> -> Pair(List<a, A>, List<a, A>)

def deal source · line 128 · raw

@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> Pair(List<a, A>, List<a, A>)

xs dealt into two halves, each in order: those at even positions, and those at odd ones.

Templates

template any.go source · line 43 · raw

@-A:Data -> @-f:(@_:A -> Bool) -> @xs:List<&2, A> -> @found:Bool -> Bool

template any source · line 53 · raw

@-A:Data -> @-f:(@_:A -> Bool) -> @xs:List<&2, A> -> Bool

Whether f holds for some x of xs; it stops at the first.

template sort.pass source · line 71 · raw

@-A:Data -> @-le:(@_:A -> @_:A -> Bool) -> @+n:Nat -> @runs:List<&2, List<&2, A>> -> @out:List<&2, List<&2, A>> -> List<&2, List<&2, A>>

One pass: each two runs merged, in order.

template sort.go source · line 87 · raw

@-A:Data -> @-le:(@_:A -> @_:A -> Bool) -> @fuel:Nat -> @+n:Nat -> @runs:List<&2, List<&2, A>> -> List<&2, A>

Passes until one run is left; each pass halves the runs, so fuel (the length) is more than enough.

template sort source · line 105 · raw

@-A:Data -> @-le:(@_:A -> @_:A -> Bool) -> @xs:List<&2, A> -> List<&2, A>

xs in le order, stable: a bottom-up merge sort.