shared.bend checks
raw source on the hub · import bend-lint-api@0.3.7.0/shared.bend as Shared
Helpers for any program of this repo, by concept. Each name starts with its concept: Lists, Names, Sets, Strings, Tables.
1 import
import Base
Types
type Names.Named source · line 138 · raw
@-A:Data -> Data
Names ===== A value, with the name it is written as.
Names.Named@-A:Data -> @name:String -> @value:A -> Names.Named<A>
type Tables.Table source · line 322 · raw
@-A:Data -> Data
Tables ====== Values by number, from 0: a balanced tree. Each node parts its values by a bit of their number, the lowest first, so a lookup reads the bits of a number, and no text.
Tables.TLeaf@-A:Data -> @value:Maybe<&2, A> -> Tables.Table<A>
Tables.TNode@-A:Data -> @even:Tables.Table<A> -> @odd:Tables.Table<A> -> Tables.Table<A>
Definitions
def Lists.when source · line 9 · raw
@-A:Data -> @hit:Bool -> @v:A -> Maybe<&2, A>
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.
def Lists.onto source · line 17 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @out:List<a, A> -> List<a, A>
xs, last first, onto out.
def Lists.append source · line 24 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @ys:List<a, A> -> List<a, A>
def Lists.concat.go source · line 27 · raw
@-a:Quant -> @-A:Kind(a) -> @xss:List<a, List<a, A>> -> @out:List<a, A> -> List<a, A>
def Lists.concat source · line 34 · raw
@-a:Quant -> @-A:Kind(a) -> @xss:List<a, List<a, A>> -> List<a, A>
def Lists.length.go source · line 37 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @n:Nat -> Nat
def Lists.length source · line 44 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> Nat
def Lists.push source · line 60 · raw
@-A:Data -> @x:Maybe<&2, A> -> @out:List<&2, A> -> List<&2, A>
def Lists.sort.runs source · line 67 · raw
@-A:Data -> @xs:List<&2, A> -> @out:List<&2, List<&2, A>> -> List<&2, List<&2, A>>
def Lists.deal.go source · line 114 · 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 Lists.deal source · line 132 · 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.
def Names.lookup.go source · line 141 · raw
@-A:Data -> @+key:String -> @table:List<&2, Names.Named<A>> -> @found:Maybe<&2, A> -> Maybe<&2, A>
def Names.lookup source · line 164 · raw
@-A:Data -> @key:String -> @table:List<&2, Names.Named<A>> -> Maybe<&2, A>
The value key names in table: the first, read no further.
def Names.find source · line 169 · raw
@-A:Data -> @table:Map<&2, Maybe<&2, A>> -> @key:String -> Maybe<&2, A>
The value key names in table, a map by name (as Lint.definitions makes): one pass over the name, however many
names there are.
def Names.Group.add.of source · line 175 · raw
@-A:Data -> @got:Pair(Map<&2, List<&2, A>>, List<&2, A>) -> @key:String -> @x:A -> Map<&2, List<&2, A>>
Groups ====== Values by name, in a map: each name's values, last first.
def Names.Group.add source · line 186 · raw
@-A:Data -> @groups:Map<&2, List<&2, A>> -> @+key:String -> @x:A -> Map<&2, List<&2, A>>
groups with x added under key. A key's list is last first; Group.get gives it in order.
def Names.Group.get source · line 195 · raw
@-A:Data -> @groups:Map<&2, List<&2, A>> -> @key:String -> List<&2, A>
What is added under key, in the order added.
def Sets.has source · line 217 · raw
@set:Set -> @key:String -> Bool
Sets ==== Set helpers. Base's Set.has gives the set back beside its answer; these give the answer alone.
def Sets.has_any source · line 221 · raw
@keys:List<&2, String> -> @+set:Set -> @found:Bool -> Bool
Whether one of keys is in set, or found.
def Strings.take.go source · line 232 · raw
@n:Nat -> @s:String -> @acc:String -> String
Strings =======
def Strings.take source · line 240 · raw
@s:String -> @n:Nat -> String
The first n characters of s. Base's String.take is not tail-recursive, so long text would overflow the stack.
def Strings.slice source · line 244 · raw
@text:String -> @+beg:U32 -> @end:U32 -> String
The text of text from beg to end, in code points.
def Strings.line_start.go source · line 247 · raw
@s:String -> @+i:U32 -> @+at:U32 -> @start:U32 -> @going:Bool -> U32
def Strings.line_start source · line 263 · raw
@text:String -> @+at:U32 -> U32
Where the line of text that holds the offset at starts: after the last newline before it.
def Strings.line_end.go source · line 266 · raw
@s:String -> @i:U32 -> U32
def Strings.line_end source · line 276 · raw
@text:String -> @+beg:U32 -> U32
Where the line of text that starts at beg ends: after its newline, or at the end of the text.
def Strings.starts_with source · line 279 · raw
@s:String -> @c:Char -> Bool
def Strings.before.go source · line 286 · raw
@s:String -> @+sep:Char -> @acc:String -> @at:Bool -> String
def Strings.before source · line 296 · raw
@+s:String -> @+sep:Char -> String
What comes before the first sep of s, or "" if there is none.
def Strings.after_last.go source · line 299 · raw
@s:String -> @+sep:Char -> @seg:String -> String
def Strings.after_last source · line 307 · raw
@s:String -> @sep:Char -> String
What comes after the last sep of s, or all of s if there is none.
def Strings.onto source · line 311 · raw
@chunks:List<&2, String> -> @out:String -> String
The chunks of chunks (last first) as one text, before out. Each chunk is copied once, so it is linear.
def Tables.Table.get.go source · line 330 · raw
@-A:Data -> @t:Tables.Table<A> -> @+i:U32 -> @odd:Bool -> Maybe<&2, A>
The value numbered i in t: odd is whether i is.
def Tables.Table.get source · line 339 · raw
@-A:Data -> @t:Tables.Table<A> -> @+i:U32 -> Maybe<&2, A>
def Tables.Table.set.go source · line 344 · raw
@-A:Data -> @fuel:Nat -> @t:Tables.Table<A> -> @+i:U32 -> @x:A -> @odd:Bool -> @zero:Bool -> Tables.Table<A>
t with x numbered i: odd is whether i is, and zero whether it is 0. A leaf of another number parts
first. fuel bounds the levels: two a bit.
def Tables.Table.set source · line 395 · raw
@-A:Data -> @t:Tables.Table<A> -> @+i:U32 -> @x:A -> Tables.Table<A>
Templates
template Lists.any.go source · line 47 · raw
@-A:Data -> @-f:(@_:A -> Bool) -> @xs:List<&2, A> -> @found:Bool -> Bool
template Lists.any source · line 57 · 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 Lists.sort.pass source · line 75 · 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 Lists.sort.go source · line 91 · 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 Lists.sort source · line 109 · raw
@-A:Data -> @-le:(@_:A -> @_:A -> Bool) -> @xs:List<&2, A> -> List<&2, A>
xs in le order, stable: a bottom-up merge sort.
template Names.table source · line 156 · raw
@-A:Data -> @-show:(@_:A -> String) -> @xs:List<&2, A> -> List<&2, Names.Named<A>>
Each of xs with the name show gives it: a table for lookup, so that each name is written once, in show.
template Names.Group.of source · line 202 · raw
@-A:Data -> @-key:(@_:A -> String) -> @xs:List<&2, A> -> @groups:Map<&2, List<&2, A>> -> Map<&2, List<&2, A>>