guarded and guardedA added to root.

This commit is contained in:
Stephen Diehl
2016-10-14 11:03:37 +01:00
parent c061df8f06
commit a86046b654
2 changed files with 10 additions and 11 deletions
+9 -1
View File
@@ -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 #-}