relude-0.7.0.0: Safe, performant, user-friendly and lightweight Haskell Standard Library

Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2020 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellSafe
LanguageHaskell2010

Relude.Functor.Fmap

Description

This module contains useful functions to work with Functor type class.

Synopsis

Documentation

(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) infixl 4 Source #

Alias for fmap . fmap. Convenient to work with two nested Functors.

>>> negate <<$>> Just [1,2,3]
Just [-1,-2,-3]

(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 #

Flipped version of <$>.

(<&>) = flip fmap

Examples

Expand

Apply (+1) to a list, a Just and a Right:

>>> Just 2 <&> (+1)
Just 3
>>> [1,2,3] <&> (+1)
[2,3,4]
>>> Right 3 <&> (+1)
Right 4

Since: base-4.11.0.0

flap :: Functor f => f (a -> b) -> a -> f b Source #

Takes a function in a Functor context and applies it to a normal value.

>>> flap (++) "relude" "P"
"Prelude"

Since: 0.3.0

(??) :: Functor f => f (a -> b) -> a -> f b infixl 4 Source #

Operator version of the flap function.

>>> [(+2), (*3)] ?? 5
[7,15]
>>> Just (+3) ?? 5
Just 8

Since: 0.3.0