Skip to content

Commit

Permalink
Update README.md for reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Kaliakatsos committed Apr 14, 2023
1 parent 98194f8 commit 2de61f3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const fcpp::vector<int> numbers({1, 4, 2, 5, 8, 3, 1, 7, 1});
const fcpp::set<int> unique_numbers = numbers.distinct();
```
### zip, map, filter, sort
### zip, map, filter, sort, reduce
```c++
#include "vector.h" // instead of <vector>
Expand Down Expand Up @@ -129,6 +129,11 @@ const auto employees_below_40 = ages
employees_below_40.for_each([](const person& p) {
std::cout << p.name << " is " << p.age << " years old." << std::endl;
});
// total_age = 92
const auto total_age = employees_below_40.reduce(0, [](const int& partial_sum, const person& p){
return partial_sum + p.age;
});
```
### index search
```c++
Expand Down Expand Up @@ -321,7 +326,7 @@ const auto friends_and_family = friends.union_with(family);
const fcpp::vector<person> = friends_and_family.keys();
```
### zip, map, filter
### zip, map, filter, reduce
```c++
#include "set.h" // instead of <set>
Expand Down Expand Up @@ -353,6 +358,11 @@ const auto employees_below_40 = ages
employees_below_40.for_each([](const person& p) {
std::cout << p.name << " is " << p.age << " years old." << std::endl;
});
// total_age = 55
const auto total_age = employees_below_40.reduce(0, [](const int& partial_sum, const person& p){
return partial_sum + p.age;
});
```

### all_of, any_of, none_of
Expand Down

0 comments on commit 2de61f3

Please sign in to comment.