Some basic functional programming.
Implemented a functional list representation using callable objects, where a list l
of type L
supports operations via the method:
template <typename F, typename A>
A operator()(F f, A a);
with f
being a callable of the form:
template <typename X>
A operator()(X x, A a);
Lists implicitly store elements
Implemented operations:
empty
: represents an empty list.size(l)
: returns the size of list l.cons(x, l)
: prepends x to list l.create(...)
: constructs a list from given elements.of_range(r)
: creates a list from a bidirectional ranger
.concat(l, k)
: concatenates listsl
andk
.rev(l)
: reverses the listl
.map(m, l)
: appliesm(x)
to each elementx
inl
.filter(p, l)
: keeps elementsx
inl
wherep(x)
is true.flatten(l)
: concatenates nested lists inl
.as_string(l)
: convertsl
tostd::string
, assumingoperator<<
is defined for elements.