Skip to content

Commit 2de61f3

Browse files
author
Ioannis Kaliakatsos
committed
Update README.md for reduce
1 parent 98194f8 commit 2de61f3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const fcpp::vector<int> numbers({1, 4, 2, 5, 8, 3, 1, 7, 1});
7272
const fcpp::set<int> unique_numbers = numbers.distinct();
7373
```
7474
75-
### zip, map, filter, sort
75+
### zip, map, filter, sort, reduce
7676
```c++
7777
#include "vector.h" // instead of <vector>
7878
@@ -129,6 +129,11 @@ const auto employees_below_40 = ages
129129
employees_below_40.for_each([](const person& p) {
130130
std::cout << p.name << " is " << p.age << " years old." << std::endl;
131131
});
132+
133+
// total_age = 92
134+
const auto total_age = employees_below_40.reduce(0, [](const int& partial_sum, const person& p){
135+
return partial_sum + p.age;
136+
});
132137
```
133138
### index search
134139
```c++
@@ -321,7 +326,7 @@ const auto friends_and_family = friends.union_with(family);
321326
const fcpp::vector<person> = friends_and_family.keys();
322327
```
323328
324-
### zip, map, filter
329+
### zip, map, filter, reduce
325330
```c++
326331
#include "set.h" // instead of <set>
327332
@@ -353,6 +358,11 @@ const auto employees_below_40 = ages
353358
employees_below_40.for_each([](const person& p) {
354359
std::cout << p.name << " is " << p.age << " years old." << std::endl;
355360
});
361+
362+
// total_age = 55
363+
const auto total_age = employees_below_40.reduce(0, [](const int& partial_sum, const person& p){
364+
return partial_sum + p.age;
365+
});
356366
```
357367

358368
### all_of, any_of, none_of

0 commit comments

Comments
 (0)