New Algorithms - A Functional Perspective
This lesson gives an overview of the new algorithms that are a part of C++17.
All new functions have a pendant in the purely functional language Haskell.
Functions | Haskell |
---|---|
std::for_each_n |
map |
std::exclusive_scan |
scanl |
std::inclusive_scan |
scanl1 |
std::transform_exclusive_scan and std::transform_inclusive_scan |
composition of map and scanl or scanl1 |
std::reduce |
foldl or foldl1 |
transform_reduce |
composition of map and foldl or foldl1 |
Before I show you Haskell in action, let me briefly discuss the different functions.
Functions | Description |
---|---|
map |
applies a function to a list |
foldl and foldl1 |
apply a binary operation to a list and reduce the list to a value. foldl needs, in contrast to foldl1 , an initial value. |
scanl and scanl1 |
apply the same strategy as foldl and foldl1 but produce all intermediate results so that you will get back a list |
- Note:
foldl
,foldl1
,scanl
, andscanl1
start their job from the left.
Let’s have a look at the running example of Haskell functions:
Get hands-on with 1400+ tech skills courses.