An Algebraic Effect System for Golang.
at main 17 lines 403 B view raw
1package rw 2 3import "github.com/vic/fx.go/fx" 4 5type Reader[T any] func() *T 6 7type ReadFn[T any] func(fx.Nil) fx.FxPure[*T] 8type ReadAb[T any] = fx.And[ReadFn[T], fx.Nil] 9type ReadFx[T, V any] = fx.Fx[ReadAb[T], V] 10 11func Read[T any]() ReadFx[T, *T] { 12 return fx.Suspend[ReadFn[T]](fx.PNil) 13} 14 15func ReadService[T any](r Reader[T]) ReadFn[T] { 16 return func(_ fx.Nil) fx.FxPure[*T] { return fx.Pure(r()) } 17}