-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (34 loc) · 1.23 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "funcy/funcy.h"
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
std::vector<int> v{1, 2, 3, 4, 5, 6};
std::cout << "v:" << std::endl;
for (const auto& val : v) {
std::cout << val << std::endl;
}
auto v2 = iter(v).map([](auto a){ return a * 2; }).collect();
std::cout << "v2:" << std::endl;
for (const auto& val : v2) {
std::cout << val << std::endl;
}
auto v3 = iter(v).filter([](auto a) { return a > 0; }).collect();
std::cout << "v3:" << std::endl;
for (const auto& val : v3) {
std::cout << val << std::endl;
}
std::cout << "sum = " << iter(v).fold(0, std::plus<int>()) << std::endl;
std::vector<bool> vb{true, true, true};
std::cout << "vb, all = " << iter(vb).all() << ", any = " << iter(vb).any() << std::endl;
auto vr = range(0, 10).map([](auto a){ return a * a; }).collect();
std::cout << "vr:" << std::endl;
for (const auto& val : vr) {
std::cout << val << std::endl;
}
auto vs = range(0, 10).scan(0, [](auto& acc, auto a){ acc += a; return acc; }).collect();
std::cout << "vs:" << std::endl;
for (const auto& val : vs) {
std::cout << val << std::endl;
}
return 0;
}