From 0ab61665eea9e1ac907b6d446d2780f841c33fba Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 11 Feb 2017 14:52:56 +0000 Subject: [PATCH] liftIO1 and liftIO2 for issue #38 --- src/Protolude.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Protolude.hs b/src/Protolude.hs index 008271478..91a304680 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -23,6 +23,8 @@ module Protolude ( guardedA, LText, LByteString, + liftIO1, + liftIO2, #if !MIN_VERSION_base(4,8,0) (&), #endif @@ -566,6 +568,7 @@ throwTo tid e = liftIO (Control.Exception.throwTo tid e) foreach :: Functor f => f a -> (a -> b) -> f b foreach = flip fmap +-- | Do nothing returning unit inside applicative. pass :: Applicative f => f () pass = pure () @@ -575,6 +578,14 @@ guarded p x = X.bool empty (pure x) (p x) guardedA :: (Functor f, Alternative t) => (a -> f Bool) -> a -> f (t a) guardedA p x = X.bool empty (pure x) <$> p x +-- | Lift an 'IO' operation with 1 argument into another monad +liftIO1 :: MonadIO m => (a -> IO b) -> a -> m b +liftIO1 = (.) liftIO + +-- | Lift an 'IO' operation with 2 arguments into another monad +liftIO2 :: MonadIO m => (a -> b -> IO c) -> a -> b -> m c +liftIO2 = ((.).(.)) liftIO + show :: (Show a, StringConv String b) => a -> b show x = toS (PBase.show x) {-# SPECIALIZE show :: Show a => a -> Text #-}