lens-3.10: Lenses, Folds and Traversals

Portabilityportable
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Inferred

Control.Lens.Combinators

Description

These are general purpose combinators that provide utility for non-lens code

Synopsis

Documentation

(&) :: a -> (a -> b) -> bSource

Passes the result of the left side to the function on the right side (forward pipe operator).

This is the flipped version of ($), which is more common in languages like F# as (|>) where it is needed for inference. Here it is supplied for notational convenience and given a precedence that allows it to be nested inside uses of ($).

>>> a & f
f a
>>> "hello" & length & succ
6

This combinator is commonly used when applying multiple Lens operations in sequence.

>>> ("hello","world") & _1.element 0 .~ 'j' & _1.element 4 .~ 'y'
("jelly","world")

This reads somewhat similar to:

>>> flip execState ("hello","world") $ do _1.element 0 .= 'j'; _1.element 4 .= 'y'
("jelly","world")

(<&>) :: Functor f => f a -> (a -> b) -> f bSource

Infix flipped fmap.

 (<&>) = flip fmap

(??) :: Functor f => f (a -> b) -> a -> f bSource

This is convenient to flip argument order of composite functions.

>>> over _2 ?? ("hello","world") $ length
("hello",5)
>>> over ?? length ?? ("hello","world") $ _2
("hello",5)