guarded and guardedA added to root.
This commit is contained in:
+1
-10
@@ -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
|
||||
|
||||
|
||||
+9
-1
@@ -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 #-}
|
||||
|
||||
Reference in New Issue
Block a user