-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
90 lines (79 loc) · 2.14 KB
/
main.cc
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "indefinite_stream.hpp"
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace indefinite;
int main()
{
std::cout << "stream[3]-> *10, divide 5, divide 9:" << '\n';
IndefiniteStream<int> a1(IndefiniteStream<int>::Start(3));
IndefiniteStream<int> a2(a1);
IndefiniteStream<int> a = std::move(a2);
a.scale_before(
[](int value) {
return value * 10;
})
.filter(
[](int value) {
return (value % 5 == 0);
})
.filter(
[](int value) {
return (value % 9 == 0);
});
std::cout << "top: "<< a.top() << '\n';
std::cout << "pop: " << a.pop() << '\n';
std::cout << "pop: " << a.pop() << '\n';
std::cout << "pop: " << a.pop() << '\n';
std::cout << "pop: " << a.pop() << '\n';
std::cout << '\n';
int size = 100;
std::cout << "stream[2, 5]-> divide 7, divide 11, * 10:" << '\n';
std::cout << "Get " << size << " numbers: " << '\n';
indefinite::IndefiniteStream<int> b(IndefiniteStream<int>::Start(2), IndefiniteStream<int>::Step(5));
std::vector<int> v = b.filter(
[](int value) {
return (value % 7 == 0);
})
.filter(
[](int value) {
return (value % 11 == 0);
})
.scale_after(
[](int value) {
return value * 10;
})
.limit(size);
std::for_each(v.begin(), v.end(),
[](int value){ std::cout << value << ' '; });
std::cout << '\n';
std::cout << '\n';
IndefiniteStream<int> s(IndefiniteStream<int>::Start(1));
auto sum = s.accumulate(size, 0);
std::cout << "Get 1-"<< size <<" sum: " << sum << '\n';
std::cout << '\n';
std::cout << "Get " << size << " primes numbers: " << '\n';
IndefiniteStream<int> primes(IndefiniteStream<int>::Start(2));
std::vector<int> vp = primes.filter(
[](int value) {
if (value < 2) {
return false;
}
else if (value == 2) {
return true;
}
for(int i = 2; i <= std::sqrt(value); ++i) {
if (value % i == 0) {
return false;
}
}
return true;
})
.limit(size);
for (auto v : vp) {
std::cout << v << ' ';
}
std::cout << '\n';
return 0;
}