diff --git a/src/Applicative.hs b/src/Applicative.hs index 063ba4abc..2bdaab0be 100644 --- a/src/Applicative.hs +++ b/src/Applicative.hs @@ -5,16 +5,13 @@ module Applicative ( orAlt, orEmpty, eitherA, - guarded, - guardedA, purer, liftAA2, (<<*>>), ) where -import Data.Bool (Bool, bool) +import Data.Bool (Bool) import Data.Function ((.)) -import Data.Functor (Functor) import Data.Either (Either(..)) import Data.Monoid (Monoid(..)) import Control.Applicative @@ -28,12 +25,6 @@ orEmpty b a = if b then pure a else empty eitherA :: (Alternative f) => f a -> f b -> f (Either a b) eitherA a b = (Left <$> a) <|> (Right <$> b) -guarded :: (Alternative f) => (a -> Bool) -> a -> f a -guarded p x = bool empty (pure x) (p x) - -guardedA :: (Functor f, Alternative t) => (a -> f Bool) -> a -> f (t a) -guardedA p x = bool empty (pure x) <$> p x - purer :: (Applicative f, Applicative g) => a -> f (g a) purer = pure . pure diff --git a/src/Protolude.hs b/src/Protolude.hs index 32b8d786f..f78d5f05a 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -20,7 +20,8 @@ module Protolude ( foreach, show, pass, - + guarded, + guardedA, LText, LByteString, ) where @@ -404,6 +405,13 @@ foreach = flip fmap pass :: Applicative f => f () pass = pure () +guarded :: (Alternative f) => (a -> Bool) -> a -> f a +guarded p x = bool empty (pure x) (p x) + +guardedA :: (Functor f, Alternative t) => (a -> f Bool) -> a -> f (t a) +guardedA p x = bool empty (pure x) <$> p x + + show :: (Show a, StringConv String b) => a -> b show x = toS (PBase.show x) {-# SPECIALIZE show :: Show a => a -> Text #-}