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(src: iterator<auto(TT)>; blk: lambda<(what:TT const):bool> const)

filter returns auto

argument

argument type

src

iterator<auto(TT)>

blk

lambda<(what:TT const):bool> const

iterates over src and yields only those elements for which blk returns true filter with function

filter(src: iterator<auto(TT)>; blk: function<(what:TT const):bool> const)

filter returns auto

argument

argument type

src

iterator<auto(TT)>

blk

function<(what:TT const):bool> const

iterates over src and yields only those elements for which blk returns true filter with function

map(src: iterator<auto(TT)>; blk: lambda<(what:TT const):auto(QQ)> const)

map returns auto

argument

argument type

src

iterator<auto(TT)>

blk

lambda<(what:TT const):auto(QQ)> const

reduce value, any invokable

map(src: iterator<auto(TT)>; blk: function<(what:TT const):auto(QQ)> const)

map returns auto

argument

argument type

src

iterator<auto(TT)>

blk

function<(what:TT const):auto(QQ)> const

reduce value, any invokable

reduce(it: iterator<auto(TT)> const; blk: lambda<(left:TT const;right:TT const):TT const> const)

reduce returns auto

argument

argument type

it

iterator<auto(TT)> const

blk

lambda<(left:TT const;right:TT const):TT const> const

summ of all elements

reduce(it: iterator<auto(TT)> const; blk: function<(left:TT const;right:TT const):TT const> const)

reduce returns auto

argument

argument type

it

iterator<auto(TT)> const

blk

function<(left:TT const;right:TT const):TT const> const

summ of all elements

reduce(it: iterator<auto(TT)> const; blk: block<(left:TT const;right:TT const):TT const> const)

reduce returns auto

argument

argument type

it

iterator<auto(TT)> const

blk

block<(left:TT const;right:TT const):TT const> const

summ of all elements

sum(it: iterator<auto(TT)> const)

sum returns auto

argument

argument type

it

iterator<auto(TT)> const

iterates over it and yields the sum of all elements same as reduce(it, @(a,b) => a + b) any

any(it: auto const)

any returns auto

argument

argument type

it

auto const

iterates over it and yields true if any element is true all

all(it: auto const)

all returns auto

argument

argument type

it

auto const

iterates over it and yields true if all elements are true

cycle(src: iterator<auto(TT)>)

cycle returns auto

argument

argument type

src

iterator<auto(TT)>

endlessly iterates over src

islice(src: iterator<auto(TT)>; start: int const; stop: int const)

islice returns auto

argument

argument type

src

iterator<auto(TT)>

start

int const

stop

int const

iterates over src and yields only the elements in the range [start,stop) [[ value; value; value; …. count times ]]

repeat_ref(value: auto(TT) const; total: int)

repeat_ref returns auto

argument

argument type

value

auto(TT) const

total

int

yields value by reference count times [[ value; value; value; …. count times ]]

repeat(value: auto(TT) const; count: int)

repeat returns auto

argument

argument type

value

auto(TT) const

count

int

yields value count times

not(x: auto const)

not returns auto

argument

argument type

x

auto const

yeilds !x

echo(x: auto; extra: string const)

echo returns auto

argument

argument type

x

auto

extra

string const

prints contents of the string to the output, with extra string appended

flatten(it: iterator<auto(TT)>)

flatten returns auto

argument

argument type

it

iterator<auto(TT)>

iterates over it, than iterates over each element of each element of it and yields it

16.2. Queries

is_equal(a: auto const; b: auto const)

is_equal returns auto

argument

argument type

a

auto const

b

auto const

yields true if a and b are equal

is_not_equal(a: auto const; b: auto const)

is_not_equal returns auto

argument

argument type

a

auto const

b

auto const

yields true if a and b are not equal

16.3. Uncategorized

sorted(arr: array<auto>)

sorted returns auto

argument

argument type

arr

array<auto>

iterates over input and returns it sorted version

sorted(it: iterator<auto(TT)>)

sorted returns auto

argument

argument type

it

iterator<auto(TT)>

iterates over input and returns it sorted version