Relude.Functor.Fmap

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

Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik
License | MIT
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | Safe
Language | Haskell2010

Relude.Functor.Fmap

Description

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

Synopsis

- (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- flap :: Functor f => f (a -> b) -> a -> f b
- (??) :: Functor f => f (a -> b) -> a -> f b

# Documentation

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

Alias for `fmap . fmap`. Convenient to work with two nested `Functor`s.

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

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

Flipped version of `<$>`.

    (<&>) = flip fmap

@since base-4.11.0.0

#### 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

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

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 #

Operator version of the `flap` function.

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

    >>> Just (+3) ?? 5
    Just 8

Since: 0.3.0