-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
io_either.go
139 lines (115 loc) · 3.88 KB
/
io_either.go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package mo
// NewIOEither instanciates a new IO.
func NewIOEither[R any](f fe0[R]) IOEither[R] {
return IOEither[R]{
unsafePerform: f,
}
}
// IOEither represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither[R any] struct {
unsafePerform fe0[R]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither[R]) Run() Either[error, R] {
v, err := io.unsafePerform()
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}
// NewIOEither1 instanciates a new IO1.
func NewIOEither1[R any, A any](f fe1[R, A]) IOEither1[R, A] {
return IOEither1[R, A]{
unsafePerform: f,
}
}
// IOEither1 represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither1[R any, A any] struct {
unsafePerform fe1[R, A]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither1[R, A]) Run(a A) Either[error, R] {
v, err := io.unsafePerform(a)
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}
// NewIOEither2 instanciates a new IO2.
func NewIOEither2[R any, A any, B any](f fe2[R, A, B]) IOEither2[R, A, B] {
return IOEither2[R, A, B]{
unsafePerform: f,
}
}
// IOEither2 represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither2[R any, A any, B any] struct {
unsafePerform fe2[R, A, B]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither2[R, A, B]) Run(a A, b B) Either[error, R] {
v, err := io.unsafePerform(a, b)
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}
// NewIOEither3 instanciates a new IO3.
func NewIOEither3[R any, A any, B any, C any](f fe3[R, A, B, C]) IOEither3[R, A, B, C] {
return IOEither3[R, A, B, C]{
unsafePerform: f,
}
}
// IOEither3 represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither3[R any, A any, B any, C any] struct {
unsafePerform fe3[R, A, B, C]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither3[R, A, B, C]) Run(a A, b B, c C) Either[error, R] {
v, err := io.unsafePerform(a, b, c)
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}
// NewIOEither4 instanciates a new IO4.
func NewIOEither4[R any, A any, B any, C any, D any](f fe4[R, A, B, C, D]) IOEither4[R, A, B, C, D] {
return IOEither4[R, A, B, C, D]{
unsafePerform: f,
}
}
// IOEither4 represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither4[R any, A any, B any, C any, D any] struct {
unsafePerform fe4[R, A, B, C, D]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither4[R, A, B, C, D]) Run(a A, b B, c C, d D) Either[error, R] {
v, err := io.unsafePerform(a, b, c, d)
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}
// NewIOEither5 instanciates a new IO5.
func NewIOEither5[R any, A any, B any, C any, D any, E any](f fe5[R, A, B, C, D, E]) IOEither5[R, A, B, C, D, E] {
return IOEither5[R, A, B, C, D, E]{
unsafePerform: f,
}
}
// IOEither5 represents a non-deterministic synchronous computation that
// can cause side effects, yields a value of type `R` and can fail.
type IOEither5[R any, A any, B any, C any, D any, E any] struct {
unsafePerform fe5[R, A, B, C, D, E]
}
// Run execute the non-deterministic synchronous computation, with side effect.
func (io IOEither5[R, A, B, C, D, E]) Run(a A, b B, c C, d D, e E) Either[error, R] {
v, err := io.unsafePerform(a, b, c, d, e)
if err != nil {
return Left[error, R](err)
}
return Right[error, R](v)
}