From 45b21d50f971638d14d0e976d4647395e7742d66 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 4 Mar 2023 15:16:51 -0800 Subject: [PATCH] Add a way to only get one value out --- src/Control/Monad/Logic/Trans.purs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Control/Monad/Logic/Trans.purs b/src/Control/Monad/Logic/Trans.purs index 763441a..d1ed097 100644 --- a/src/Control/Monad/Logic/Trans.purs +++ b/src/Control/Monad/Logic/Trans.purs @@ -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)))