Add a way to only get one value out

This commit is contained in:
Danila Fedorin 2023-03-04 15:16:51 -08:00
parent f1792e6627
commit 45b21d50f9

View File

@ -1,9 +1,9 @@
module Control.Monad.Logic.Trans (SFKT, runSFKT) where
module Control.Monad.Logic.Trans (SFKT, runSFKT, runSFKTOnce) where
import Prelude (class Applicative, class Apply, class Bind, class Functor, class Monad, bind, pure, ($), (<<<), (>>=))
import Control.Monad.Logic.Class
import Control.MonadPlus (class MonadPlus, class Alternative, class Alt, class Plus, (<|>))
import Control.MonadPlus (class MonadPlus, class Alternative, class Alt, class Plus, (<|>), empty)
import Control.Monad.Reader.Class (class MonadReader, local, class MonadAsk, ask)
import Control.Monad.State.Class (class MonadState, state)
import Control.Monad.Trans.Class (class MonadTrans, lift)
@ -27,6 +27,9 @@ unSFKT (SFKT f) = f
runSFKT :: forall a m. Applicative m => SFKT m a -> m (List a)
runSFKT (SFKT f) = f (map <<< (:)) (pure Nil)
runSFKTOnce :: forall a m. MonadPlus m => SFKT m a -> m a
runSFKTOnce (SFKT f) = f ((<|>) <<< pure) empty
instance Functor (SFKT m) where
map f m = SFKT (\sk -> unSFKT m (\a -> sk (f a)))