-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheither_main.cpp
More file actions
55 lines (44 loc) · 1.33 KB
/
Copy patheither_main.cpp
File metadata and controls
55 lines (44 loc) · 1.33 KB
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
#include <iostream>
#include <typeinfo>
#include "include/Either.h"
int main()
{
auto x = Left<int, std::string>(5);
auto y = Right<int, std::string>("5");
auto e1 = Either<int, std::string>(5);
auto e2 = Either<int, std::string>("7");
std::cout << *fromLeft(e1) << '\n';
std::cout << (fromLeft(e2) ? "1" : "0") << '\n';
std::cout << *fromRight(e2) <<'\n';
std::cout << (fromRight(e1) ? "1" : "0") << '\n';
std::vector<Either<int, std::string>> sample = {
{ 1 },
{ "2" },
{ 3 },
{ "4" },
{ 5 },
{ "6" },
{ "7" },
{ "8" },
{ 14 }
};
puts("testing lefts");
for (auto num : lefts(sample)) { std::cout << num << '\n'; }
puts("testing rights");
for (auto str : rights(sample)) { std::cout << str << '\n'; }
auto vec = partitionEithers<int, std::string>(sample);
puts("testing partitionEithers lefts");
for (auto item : vec.lefts) { std::cout << item << '\n'; }
puts("testing partition rights");
for (auto item : vec.rights) { std::cout << item << '\n'; }
puts("testingeither funciton");
std::cout << either(
[](int a) -> std::string { return std::to_string(a) + "--"; },
[](std::string a) -> std::string { return a + "_"; },
e1) << '\n';
std::cout << either(
[](auto a) -> std::string { return std::to_string(a) + "--"; },
[](auto a) -> std::string { return a + "_"; },
e2) << '\n';
return 0;
}