diff --git a/src/Protolude.hs b/src/Protolude.hs index a7d040edc..0a2665b88 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -17,7 +17,6 @@ module Protolude ( print, throwIO, throwTo, - foreach, (<&>), show, pass, guarded, @@ -590,16 +589,6 @@ throwIO = liftIO . Control.Exception.throwIO throwTo :: (X.MonadIO m, Exception e) => ThreadId -> e -> m () throwTo tid e = liftIO (Control.Exception.throwTo tid e) -foreach :: Functor f => f a -> (a -> b) -> f b -foreach = flip fmap - --- | Infix version of foreach. --- --- @<&>@ is to '<$>' what '&' is to '$'. -infixl 4 <&> -(<&>) :: Functor f => f a -> (a -> b) -> f b -(<&>) = foreach - -- | Do nothing returning unit inside applicative. pass :: Applicative f => f () pass = pure () diff --git a/src/Protolude/Functor.hs b/src/Protolude/Functor.hs index f5345becb..ae4c00298 100644 --- a/src/Protolude/Functor.hs +++ b/src/Protolude/Functor.hs @@ -7,10 +7,17 @@ module Protolude.Functor ( ($>), (<$>), (<<$>>), + (<&>), void, + foreach, ) where import Data.Function ((.)) +import Data.Function (flip) + +#if MIN_VERSION_base(4,11,0) +import Data.Functor ((<$>)) +#endif #if MIN_VERSION_base(4,7,0) import Data.Functor ( @@ -25,7 +32,6 @@ import Data.Functor ( , (<$>) ) -import Data.Function (flip) infixl 4 $> @@ -40,3 +46,16 @@ infixl 4 <<$>> (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) (<<$>>) = fmap . fmap + +foreach :: Functor f => f a -> (a -> b) -> f b +foreach = flip fmap + +#if !MIN_VERSION_base(4,11,0) +-- | Infix version of foreach. +-- +-- @<&>@ is to '<$>' what '&' is to '$'. + +infixl 1 <&> +(<&>) :: Functor f => f a -> (a -> b) -> f b +(<&>) = foreach +#endif