16. Functional programming library

The functional module implements a collection of high-order functions and patters to expose functional programming patters to daScript.

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(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

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

iterates over src and yields the result of blk for each element

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

iterates over src and yields the result of blk for each element

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

iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result

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

iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result

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

iterates over it and yields the reduced (combined) result of blk for each element and previous reduction result

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(it: auto const)

any returns auto

argument

argument type

it

auto const

iterates over it and yields true if any element is true

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)

count(start: int; step: int)

count returns iterator<int>

argument

argument type

start

int

step

int

endlessly iterates from start and yields start+step, start+2*step, …

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

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