An Algebraic Effect System for Golang.

Comments on Halt

+11 -3
+11 -3
fx.go
··· 32 32 33 33 func Ctx[V any]() Fx[V, V] { return Func(identity[V]) } 34 34 35 - // An stopped effect that panics if resumed 35 + // An stopped effect that panics if resumed. 36 + // Only useful with Replace. 37 + // 38 + // For example, an Abort effect halts since it has no possible value for V 39 + // but then its Handler can Replace the halted effect with an Error value. 40 + // See: abort/result.go 36 41 func Halt[S, V any]() Fx[S, V] { 37 42 return Stop(func() Fx[S, V] { 38 43 return Fx[S, V]{ ··· 53 58 if e.res != nil { 54 59 return e.res() 55 60 } 56 - return e 61 + if e.imm != nil { 62 + return Const[S](e.imm()) 63 + } 64 + return Pending(func(s S) Fx[S, V] { return Resume(e.sus(s)) }) 57 65 } 58 66 59 67 // Replace with y if x is already Halted. Otherwise x continues. ··· 232 240 func Eval[V any](e Fx[Nil, V]) V { 233 241 for { 234 242 if e.res != nil { 235 - panic("tried to evaluate halted effect. try using fx.Replace with another effect.") 243 + panic("tried to evaluate an stopped effect. try using fx.Resume or fx.Replace on it.") 236 244 } 237 245 if e.imm != nil { 238 246 return e.imm()