tangled
alpha
login
or
join now
oeiuwq.com
/
fx.go
0
fork
atom
An Algebraic Effect System for Golang.
0
fork
atom
overview
issues
pulls
pipelines
Rename to Then
oeiuwq.com
10 months ago
d6811eb4
89fc71f9
+6
-6
1 changed file
expand all
collapse all
unified
split
fx.go
+6
-6
fx.go
···
52
52
}
53
53
54
54
// Continue an effect by transforming its immediate value into another effect.
55
55
-
func Cont[T, U, S, V any](cmap func(T) S, fmap func(V) Fx[T, U]) func(Fx[S, V]) Fx[T, U] {
55
55
+
func Then[T, U, S, V any](cmap func(T) S, fmap func(V) Fx[T, U]) func(Fx[S, V]) Fx[T, U] {
56
56
return func(e Fx[S, V]) Fx[T, U] {
57
57
if e.stp != nil {
58
58
return Stop(func() Fx[T, U] {
59
59
-
return Cont(cmap, fmap)(e.stp())
59
59
+
return Then(cmap, fmap)(e.stp())
60
60
})
61
61
}
62
62
if e.imm != nil {
63
63
return fmap(e.imm())
64
64
}
65
65
-
return Pending(func(t T) Fx[T, U] { return Cont(cmap, fmap)(e.sus(cmap(t))) })
65
65
+
return Pending(func(t T) Fx[T, U] { return Then(cmap, fmap)(e.sus(cmap(t))) })
66
66
}
67
67
}
68
68
···
123
123
}
124
124
125
125
func FlatCont[N, A, U, B, V any](amap func(N) A, bmap func(N) B, fmap func(U) Fx[B, V]) func(Fx[A, U]) Fx[N, V] {
126
126
-
return Cont(amap, func(u U) Fx[N, V] { return Cont(bmap, Const[N, V])(fmap(u)) })
126
126
+
return Then(amap, func(u U) Fx[N, V] { return Then(bmap, Const[N, V])(fmap(u)) })
127
127
}
128
128
129
129
func AndNil[S, V any](e Fx[S, V]) Fx[And[S, Nil], V] {
130
130
-
return Cont[And[S, Nil], V](left, Const)(e)
130
130
+
return Then[And[S, Nil], V](left, Const)(e)
131
131
}
132
132
133
133
func AndSwap[A, B, V any](e Fx[And[A, B], V]) Fx[And[B, A], V] {
134
134
-
return Cont[And[B, A], V](swap[B, A], Const)(e)
134
134
+
return Then[And[B, A], V](swap[B, A], Const)(e)
135
135
}
136
136
137
137
func AndJoin[A, B, V any](e Fx[A, Fx[B, V]]) Fx[And[A, B], V] {