June 2018
Intermediate to advanced
348 pages
8h 45m
English
Map is a functional operator where a function will be applied to a list. Filter will apply a predicate to a list and return another list. They are the cornerstone of any functional processing pipeline. They are also called higher-order functions. We can write a generic Map function, using std::transform for std::list and the std::vector:
template <typename R, typename F>
R Map(R r , F&& fn) {
std::transform(std::begin(r), std::end(r), std::begin(r),
std::forward<F>(fn));
return r;
}
Let's also write a function to filter a std::list (we assume only a list will be passed). The same can work on std::vector. We can compose a higher-order function using the pipe operator. The composite function can also be ...
Read now
Unlock full access