packages feed

relude-0.4.0 / src / Relude / Functor / Fmap.hs

{-# LANGUAGE CPP  #-}{-# LANGUAGE Safe #-}{- |Copyright: (c) 2016 Stephen Diehl           (c) 20016-2018 Serokell           (c) 2018 KowainikLicense:    MITMaintainer: Kowainik <xrom.xkov@gmail.com>This module contains useful functions to work with 'Functor' type class.-}module Relude.Functor.Fmap       ( (<<$>>)       , (<&>)       , flap       , (??)       ) whereimport Relude.Function ((.))import Relude.Functor.Reexport (Functor (..))import Data.Functor ((<$>))#if MIN_VERSION_base(4,11,0)import Data.Functor ((<&>))#else-- | Flipped version of '<$>'.infixl 1 <&>(<&>) :: Functor f => f a -> (a -> b) -> f bas <&> f = f <$> as{-# INLINE (<&>) #-}#endif-- $setup-- >>> import Relude.Base (negate, (*), (+))-- >>> import Relude.Monad (Maybe (..))-- >>> import Relude.List ((++)){- | Alias for @fmap . fmap@. Convenient to work with two nested 'Functor's.>>> negate <<$>> Just [1,2,3]Just [-1,-2,-3]-}infixl 4 <<$>>(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)(<<$>>) = fmap . fmap{-# INLINE (<<$>>) #-}{- | Takes a function in a 'Functor' context and applies it to a normal value.>>> flap (++) "relude" "P""Prelude"-}flap :: Functor f => f (a -> b) -> a -> f bflap ff x = (\f -> f x) <$> ff{-# INLINE flap #-}{- | Operator version of the 'flap' function.>>> [(+2), (*3)] ?? 5[7,15]>>> Just (+3) ?? 5Just 8-}infixl 4 ??(??) :: Functor f => f (a -> b) -> a -> f b(??) = flap{-# INLINE (??) #-}