@@ -15,36 +15,22 @@ type pnil struct{}
1515var PNil Nil = Nil (pnil {})
1616var PureNil FxNil = Pure (PNil )
1717
18- func Pure [V any ](v V ) FxPure [V ] {
19- return Const [Nil ](v )
20- }
18+ func Pure [V any ](v V ) FxPure [V ] { return Const [Nil ](v ) }
2119
2220func identity [V any ](v V ) V { return v }
2321
24- func Const [S , V any ](v V ) Fx [S , V ] {
25- return Fx [S , V ]{imm : func () V { return v }}
26- }
22+ func Const [S , V any ](v V ) Fx [S , V ] { return Fx [S , V ]{imm : func () V { return v }} }
2723
28- func Pending [S , V any ](f func (S ) Fx [S , V ]) Fx [S , V ] {
29- return Fx [S , V ]{sus : f }
30- }
24+ func Pending [S , V any ](f func (S ) Fx [S , V ]) Fx [S , V ] { return Fx [S , V ]{sus : f } }
3125
3226func Func [S , V any ](f func (S ) V ) Fx [S , V ] {
3327 return Pending (func (s S ) Fx [S , V ] { return Const [S ](f (s )) })
3428}
3529
36- func Apply [F ~ func (I ) O , I , O any ](i I ) Fx [F , O ] {
37- return Map (Ctx [F ](), func (f F ) O { return f (i ) })
38- }
39-
40- func Ctx [V any ]() Fx [V , V ] {
41- return Func (identity [V ])
42- }
30+ func Ctx [V any ]() Fx [V , V ] { return Func (identity [V ]) }
4331
4432// An effect that will never be continued.
45- func Halt [S , V any ]() Fx [S , V ] {
46- return Fx [S , V ]{hlt : func () {}}
47- }
33+ func Halt [S , V any ]() Fx [S , V ] { return Fx [S , V ]{hlt : func () {}} }
4834
4935// Replace with y if x is already Halted. Otherwise x continues.
5036func Replace [S , V any ](y func () Fx [S , V ]) func (Fx [S , V ]) Fx [S , V ] {
@@ -74,12 +60,12 @@ func Cont[T, U, S, V any](cmap func(T) S, fmap func(V) Fx[T, U]) func(Fx[S, V])
7460
7561type And [A , B any ] func () (A , B )
7662
77- func rswap [A , B any ](ba And [B , A ]) And [A , B ] {
78- var ab And [A , B ] = func () (A , B ) {
79- b , a := ba ()
80- return a , b
63+ func swap [A , B any ](ab And [A , B ]) And [B , A ] {
64+ var ba And [B , A ] = func () (B , A ) {
65+ a , b := ab ()
66+ return b , a
8167 }
82- return ab
68+ return ba
8369}
8470
8571func left [A , B any ](ab And [A , B ]) A {
@@ -135,7 +121,7 @@ func AndNil[S, V any](e Fx[S, V]) Fx[And[S, Nil], V] {
135121}
136122
137123func AndSwap [A , B , V any ](e Fx [And [A , B ], V ]) Fx [And [B , A ], V ] {
138- return Cont [And [B , A ], V ](rswap , Const )(e )
124+ return Cont [And [B , A ], V ](swap [ B , A ] , Const )(e )
139125}
140126
141127func AndJoin [A , B , V any ](e Fx [A , Fx [B , V ]]) Fx [And [A , B ], V ] {
@@ -195,6 +181,10 @@ func ProvideLeft[A, B, V any](e Fx[And[A, B], V], a A) Fx[B, V] {
195181 })
196182}
197183
184+ func Apply [F ~ func (I ) O , I , O any ](i I ) Fx [F , O ] {
185+ return Map (Ctx [F ](), func (f F ) O { return f (i ) })
186+ }
187+
198188func Suspend [A ~ func (I ) Fx [B , O ], B , I , O any ](i I ) Fx [And [A , B ], O ] {
199189 return AndJoin (Apply [A ](i ))
200190}
0 commit comments