16. Functional programming library
The functional module implements a collection of high-order functions and patters to expose functional programming patters to Daslang.
All functions and symbols are in “functional” module, use require to get access to it.
require daslib/functional
16.1. Map, reduce
filter (var src: iterator<auto(TT)>; blk: lambda<(what:TT):bool>) : auto
filter (var src: iterator<auto(TT)>; blk: function<(what:TT):bool>) : auto
map (var src: iterator<auto(TT)>; blk: lambda<(what:TT):auto(QQ)>) : auto
map (var src: iterator<auto(TT)>; blk: function<(what:TT):auto(QQ)>) : auto
reduce (var it: iterator<auto(TT)>; blk: lambda<(left:TT;right:TT):TT>) : auto
reduce (var it: iterator<auto(TT)>; blk: function<(left:TT;right:TT):TT>) : auto
reduce (var it: iterator<auto(TT)>; blk: block<(left:TT;right:TT):TT>) : auto
islice (var src: iterator<auto(TT)>; start: int; stop: int) : auto
- filter(src: iterator<auto(TT)>; blk: lambda<(what:TT):bool>) : auto()
iterates over src and yields only those elements for which blk returns true
- Arguments
src : iterator<auto(TT)>
blk : lambda<(what:TT):bool>
- filter(src: iterator<auto(TT)>; blk: function<(what:TT):bool>) : auto()
iterates over src and yields only those elements for which blk returns true
- Arguments
src : iterator<auto(TT)>
blk : function<(what:TT):bool>
- map(src: iterator<auto(TT)>; blk: lambda<(what:TT):auto(QQ)>) : auto()
iterates over src and yields the result of blk for each element
- Arguments
src : iterator<auto(TT)>
blk : lambda<(what:TT):auto(QQ)>
- map(src: iterator<auto(TT)>; blk: function<(what:TT):auto(QQ)>) : auto()
iterates over src and yields the result of blk for each element
- Arguments
src : iterator<auto(TT)>
blk : function<(what:TT):auto(QQ)>
- reduce(it: iterator<auto(TT)>; blk: lambda<(left:TT;right:TT):TT>) : auto()
iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result
- Arguments
it : iterator<auto(TT)>
blk : lambda<(left:TT;right:TT):TT>
- reduce(it: iterator<auto(TT)>; blk: function<(left:TT;right:TT):TT>) : auto()
iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result
- Arguments
it : iterator<auto(TT)>
blk : function<(left:TT;right:TT):TT>
- reduce(it: iterator<auto(TT)>; blk: block<(left:TT;right:TT):TT>) : auto()
iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result
- Arguments
it : iterator<auto(TT)>
blk : block<(left:TT;right:TT):TT>
- sum(it: iterator<auto(TT)>) : auto()
iterates over it and yields the sum of all elements same as reduce(it, @(a,b) => a + b)
- Arguments
it : iterator<auto(TT)>
- any(it: auto) : auto()
iterates over it and yields true if any element is true
- Arguments
it : auto
- any(it: iterator<auto(TT)>) : auto()
iterates over it and yields true if any element is true
- Arguments
it : iterator<auto(TT)>
- all(it: auto) : auto()
iterates over it and yields true if all elements are true
- Arguments
it : auto
- all(it: iterator<auto(TT)>) : auto()
iterates over it and yields true if all elements are true
- Arguments
it : iterator<auto(TT)>
- cycle(src: iterator<auto(TT)>) : auto()
endlessly iterates over src
- Arguments
src : iterator<auto(TT)>
- islice(src: iterator<auto(TT)>; start: int; stop: int) : auto()
iterates over src and yields only the elements in the range [start,stop)
- Arguments
src : iterator<auto(TT)>
start : int
stop : int
- repeat_ref(value: auto(TT); total: int) : auto()
yields value by reference count times
- Arguments
value : auto(TT)
total : int
- repeat(value: auto(TT); count: int = 0) : auto()
yields value count times
- Arguments
value : auto(TT)
count : int
- not(x: auto) : auto()
yeilds !x
- Arguments
x : auto
- echo(x: auto; extra: string = "\n") : auto()
prints contents of the string to the output, with extra string appended
- Arguments
x : auto
extra : string
- flatten(it: iterator<auto(TT)>) : auto()
iterates over it, than iterates over each element of each element of it and yields it
- Arguments
it : iterator<auto(TT)>
- sorted(arr: array<auto>) : auto()
iterates over input and returns it sorted version
- Arguments
arr : array<auto>
- sorted(it: iterator<auto(TT)>) : auto()
iterates over input and returns it sorted version
- Arguments
it : iterator<auto(TT)>