amazonka-core-1.6.1: Core data types and functionality for Amazonka libraries.

Copyright (c) 2013-2018 Brendan Hay Mozilla Public License, v. 2.0. Brendan Hay provisional non-portable (GHC extensions) Safe Haskell2010

Network.AWS.Lens

Description

Synopsis

# Documentation

throwingM :: MonadThrow m => AReview SomeException b -> b -> m r #

A variant of throwing that can only be used within the IO Monad (or any other MonadCatch instance) to throw an Exception described by a ReifiedPrism.

Although throwingM has a type that is a specialization of the type of throwing, the two functions are subtly different:

throwing l e seq x  ≡ throwing e
throwingM l e seq x ≡ x


The first example will cause the Exception e to be raised, whereas the second one won't. In fact, throwingM will only cause an Exception to be raised when it is used within the MonadCatch instance. The throwingM variant should be used in preference to throwing to raise an Exception within the Monad because it guarantees ordering with respect to other monadic operations, whereas throwing does not.

throwingM l ≡ reviews l throw

throwingM :: MonadThrow m => Prism' SomeException t -> t -> m r
throwingM :: MonadThrow m => Iso' SomeException t   -> t -> m r


trying :: MonadCatch m => Getting (First a) SomeException a -> m r -> m (Either a r) #

A variant of try that takes a ReifiedPrism (or any ReifiedFold) to select which exceptions are caught (c.f. tryJust, catchJust). If the Exception does not match the predicate, it is re-thrown.

trying :: MonadCatch m => Prism'     SomeException a -> m r -> m (Either a r)
trying :: MonadCatch m => Lens'      SomeException a -> m r -> m (Either a r)
trying :: MonadCatch m => Traversal' SomeException a -> m r -> m (Either a r)
trying :: MonadCatch m => Iso'       SomeException a -> m r -> m (Either a r)
trying :: MonadCatch m => ReifiedGetter     SomeException a -> m r -> m (Either a r)
trying :: MonadCatch m => ReifiedFold       SomeException a -> m r -> m (Either a r)


catching_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m r -> m r #

Catch exceptions that match a given ReifiedPrism (or any ReifiedGetter), discarding the information about the match. This is particuarly useful when you have a Prism' e () where the result of the ReifiedPrism or ReifiedFold isn't particularly valuable, just the fact that it matches.

>>> catching_ _AssertionFailed (assert False (return "uncaught")) $return "caught" "caught"  catching_ :: MonadCatch m => Prism' SomeException a -> m r -> m r -> m r catching_ :: MonadCatch m => Lens' SomeException a -> m r -> m r -> m r catching_ :: MonadCatch m => Traversal' SomeException a -> m r -> m r -> m r catching_ :: MonadCatch m => Iso' SomeException a -> m r -> m r -> m r catching_ :: MonadCatch m => ReifiedGetter SomeException a -> m r -> m r -> m r catching_ :: MonadCatch m => ReifiedFold SomeException a -> m r -> m r -> m r  catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r # Catch exceptions that match a given ReifiedPrism (or any ReifiedFold, really). >>> catching _AssertionFailed (assert False (return "uncaught"))$ \ _ -> return "caught"
"caught"

catching :: MonadCatch m => Prism' SomeException a     -> m r -> (a -> m r) -> m r
catching :: MonadCatch m => Lens' SomeException a      -> m r -> (a -> m r) -> m r
catching :: MonadCatch m => Traversal' SomeException a -> m r -> (a -> m r) -> m r
catching :: MonadCatch m => Iso' SomeException a       -> m r -> (a -> m r) -> m r
catching :: MonadCatch m => ReifiedGetter SomeException a     -> m r -> (a -> m r) -> m r
catching :: MonadCatch m => ReifiedFold SomeException a       -> m r -> (a -> m r) -> m r


Traverse the strongly typed Exception contained in SomeException where the type of your function matches the desired Exception.

exception :: (Applicative f, Exception a)
=> (a -> f a) -> SomeException -> f SomeException


Unfortunately the name ioException is taken by base for throwing IOExceptions.

_IOException :: Prism' IOException IOException
_IOException :: Prism' SomeException IOException


Many combinators for working with an IOException are available in System.IO.Error.Lens.

type Getting r s a = (a -> Const r a) -> s -> Const r s #

When you see this in a type signature it indicates that you can pass the function a Lens, Getter, Traversal, Fold, Prism, Iso, or one of the indexed variants, and it will just "do the right thing".

Most Getter combinators are able to be used with both a Getter or a Fold in limited situations, to do so, they need to be monomorphic in what we are going to extract with Const. To be compatible with Lens, Traversal and Iso we also restricted choices of the irrelevant t and b parameters.

If a function accepts a Getting r s a, then when r is a Monoid, then you can pass a Fold (or Traversal), otherwise you can only pass this a Getter or Lens.

type Lens' s a = Lens s s a a #

type Lens' = Simple Lens


type Traversal' s a = Traversal s s a a #

type Traversal' = Simple Traversal


type IndexedTraversal' i s a = IndexedTraversal i s s a a #

type IndexedTraversal' i = Simple (IndexedTraversal i)


type Setter' s a = Setter s s a a #

A Setter' is just a Setter that doesn't change the types.

These are particularly common when talking about monomorphic containers. e.g.

sets Data.Text.map :: Setter' Text Char

type Setter' = Simple Setter


type Iso' s a = Iso s s a a #

type Iso' = Simple Iso


type AReview t b = Optic' (Tagged :: Type -> Type -> Type) Identity t b #

If you see this in a signature for a function, the function is expecting a Review (in practice, this usually means a Prism).

type Prism' s a = Prism s s a a #

A Simple Prism.

type Getter s a = forall (f :: Type -> Type). (Contravariant f, Functor f) => (a -> f a) -> s -> f s #

A Getter describes how to retrieve a single value in a way that can be composed with other LensLike constructions.

Unlike a Lens a Getter is read-only. Since a Getter cannot be used to write back there are no Lens laws that can be applied to it. In fact, it is isomorphic to an arbitrary function from (s -> a).

Moreover, a Getter can be used directly as a Fold, since it just ignores the Applicative.

type Fold s a = forall (f :: Type -> Type). (Contravariant f, Applicative f) => (a -> f a) -> s -> f s #

A Fold describes how to retrieve multiple values in a way that can be composed with other LensLike constructions.

A Fold s a provides a structure with operations very similar to those of the Foldable typeclass, see foldMapOf and the other Fold combinators.

By convention, if there exists a foo method that expects a Foldable (f a), then there should be a fooOf method that takes a Fold s a and a value of type s.

A Getter is a legal Fold that just ignores the supplied Monoid.

Unlike a Traversal a Fold is read-only. Since a Fold cannot be used to write back there are no Lens laws that apply.

type Optic' (p :: k1 -> k -> Type) (f :: k1 -> k) (s :: k1) (a :: k1) = Optic p f s s a a #

type Optic' p f s a = Simple (Optic p f) s a


class Profunctor p => Choice (p :: Type -> Type -> Type) #

The generalization of Costar of Functor that is strong with respect to Either.

Note: This is also a notion of strength, except with regards to another monoidal structure that we can choose to equip Hask with: the cocartesian coproduct.

Minimal complete definition

Instances
 Instance detailsDefined in Control.Lens.Reified Methodsleft' :: ReifiedGetter a b -> ReifiedGetter (Either a c) (Either b c) #right' :: ReifiedGetter a b -> ReifiedGetter (Either c a) (Either c b) # Instance detailsDefined in Control.Lens.Reified Methodsleft' :: ReifiedFold a b -> ReifiedFold (Either a c) (Either b c) #right' :: ReifiedFold a b -> ReifiedFold (Either c a) (Either c b) # Monad m => Choice (Kleisli m) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Kleisli m a b -> Kleisli m (Either a c) (Either b c) #right' :: Kleisli m a b -> Kleisli m (Either c a) (Either c b) # Instance detailsDefined in Control.Lens.Internal.Indexed Methodsleft' :: Indexed i a b -> Indexed i (Either a c) (Either b c) #right' :: Indexed i a b -> Indexed i (Either c a) (Either c b) # Profunctor p => Choice (TambaraSum p) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: TambaraSum p a b -> TambaraSum p (Either a c) (Either b c) #right' :: TambaraSum p a b -> TambaraSum p (Either c a) (Either c b) # Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: PastroSum p a b -> PastroSum p (Either a c) (Either b c) #right' :: PastroSum p a b -> PastroSum p (Either c a) (Either c b) # Choice p => Choice (Tambara p) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Tambara p a b -> Tambara p (Either a c) (Either b c) #right' :: Tambara p a b -> Tambara p (Either c a) (Either c b) # Applicative f => Choice (Star f) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Star f a b -> Star f (Either a c) (Either b c) #right' :: Star f a b -> Star f (Either c a) (Either c b) # Traversable w => Choice (Costar w) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Costar w a b -> Costar w (Either a c) (Either b c) #right' :: Costar w a b -> Costar w (Either c a) (Either c b) # Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: WrappedArrow p a b -> WrappedArrow p (Either a c) (Either b c) #right' :: WrappedArrow p a b -> WrappedArrow p (Either c a) (Either c b) # Monoid r => Choice (Forget r) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Forget r a b -> Forget r (Either a c) (Either b c) #right' :: Forget r a b -> Forget r (Either c a) (Either c b) # Choice (Tagged :: Type -> Type -> Type) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Tagged a b -> Tagged (Either a c) (Either b c) #right' :: Tagged a b -> Tagged (Either c a) (Either c b) # Choice ((->) :: Type -> Type -> Type) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: (a -> b) -> Either a c -> Either b c #right' :: (a -> b) -> Either c a -> Either c b # Comonad w => Choice (Cokleisli w) extract approximates costrength Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Cokleisli w a b -> Cokleisli w (Either a c) (Either b c) #right' :: Cokleisli w a b -> Cokleisli w (Either c a) (Either c b) # (Choice p, Choice q) => Choice (Procompose p q) Instance detailsDefined in Data.Profunctor.Composition Methodsleft' :: Procompose p q a b -> Procompose p q (Either a c) (Either b c) #right' :: Procompose p q a b -> Procompose p q (Either c a) (Either c b) # Functor f => Choice (Joker f :: Type -> Type -> Type) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Joker f a b -> Joker f (Either a c) (Either b c) #right' :: Joker f a b -> Joker f (Either c a) (Either c b) # (Choice p, Choice q) => Choice (Product p q) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Product p q a b -> Product p q (Either a c) (Either b c) #right' :: Product p q a b -> Product p q (Either c a) (Either c b) # (Functor f, Choice p) => Choice (Tannen f p) Instance detailsDefined in Data.Profunctor.Choice Methodsleft' :: Tannen f p a b -> Tannen f p (Either a c) (Either b c) #right' :: Tannen f p a b -> Tannen f p (Either c a) (Either c b) #

_last :: Snoc s s a a => Traversal' s a #

A Traversal reading and writing to the last element of a non-empty container.

>>> [a,b,c]^?!_last
c

>>> []^?_last
Nothing

>>> [a,b,c] & _last %~ f
[a,b,f c]

>>> [1,2]^?_last
Just 2

>>> [] & _last .~ 1
[]

>>> [0] & _last .~ 2
[2]

>>> [0,1] & _last .~ 2
[0,2]


This Traversal is not limited to lists, however. We can also work with other containers, such as a Vector.

>>> Vector.fromList "abcde" ^? _last
Just 'e'

>>> Vector.empty ^? _last
Nothing

>>> (Vector.fromList "abcde" & _last .~ 'Q') == Vector.fromList "abcdQ"
True

_last :: Traversal' [a] a
_last :: Traversal' (Seq a) a
_last :: Traversal' (Vector a) a


mapping :: (Functor f, Functor g) => AnIso s t a b -> Iso (f s) (g t) (f a) (g b) #

This can be used to lift any Iso into an arbitrary Functor.

iso :: (s -> a) -> (b -> t) -> Iso s t a b #

Build a simple isomorphism from a pair of inverse functions.

view (iso f g) ≡ f
view (from (iso f g)) ≡ g
over (iso f g) h ≡ g . h . f
over (from (iso f g)) h ≡ f . h . g


traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b #

Traverse any Traversable container. This is an IndexedTraversal that is indexed by ordinal position.

has :: Getting Any s a -> s -> Bool #

Check to see if this Fold or Traversal matches 1 or more entries.

>>> has (element 0) []
False

>>> has _Left (Left 12)
True

>>> has _Right (Left 12)
False


This will always return True for a Lens or Getter.

>>> has _1 ("hello","world")
True

has :: Getter s a     -> s -> Bool
has :: Fold s a       -> s -> Bool
has :: Iso' s a       -> s -> Bool
has :: Lens' s a      -> s -> Bool
has :: Traversal' s a -> s -> Bool


concatOf :: Getting [r] s [r] -> s -> [r] #

Concatenate all of the lists targeted by a Fold into a longer list.

>>> concatOf both ("pan","ama")
"panama"

concat ≡ concatOf folded
concatOf ≡ view

concatOf :: Getter s [r]     -> s -> [r]
concatOf :: Fold s [r]       -> s -> [r]
concatOf :: Iso' s [r]       -> s -> [r]
concatOf :: Lens' s [r]      -> s -> [r]
concatOf :: Traversal' s [r] -> s -> [r]


allOf :: Getting All s a -> (a -> Bool) -> s -> Bool #

Returns True if every target of a Fold satisfies a predicate.

>>> allOf both (>=3) (4,5)
True
>>> allOf folded (>=2) [1..10]
False

all ≡ allOf folded

iallOf l = allOf l . Indexed

allOf :: Getter s a     -> (a -> Bool) -> s -> Bool
allOf :: Fold s a       -> (a -> Bool) -> s -> Bool
allOf :: Lens' s a      -> (a -> Bool) -> s -> Bool
allOf :: Iso' s a       -> (a -> Bool) -> s -> Bool
allOf :: Traversal' s a -> (a -> Bool) -> s -> Bool
allOf :: Prism' s a     -> (a -> Bool) -> s -> Bool


anyOf :: Getting Any s a -> (a -> Bool) -> s -> Bool #

Returns True if any target of a Fold satisfies a predicate.

>>> anyOf both (=='x') ('x','y')
True
>>> import Data.Data.Lens
>>> anyOf biplate (== "world") (((),2::Int),"hello",("world",11::Int))
True

any ≡ anyOf folded

ianyOf l ≡ anyOf l . Indexed

anyOf :: Getter s a     -> (a -> Bool) -> s -> Bool
anyOf :: Fold s a       -> (a -> Bool) -> s -> Bool
anyOf :: Lens' s a      -> (a -> Bool) -> s -> Bool
anyOf :: Iso' s a       -> (a -> Bool) -> s -> Bool
anyOf :: Traversal' s a -> (a -> Bool) -> s -> Bool
anyOf :: Prism' s a     -> (a -> Bool) -> s -> Bool


filtered :: (Choice p, Applicative f) => (a -> Bool) -> Optic' p f a a #

Obtain an Fold that can be composed with to filter another Lens, Iso, Getter, Fold (or Traversal).

Note: This is not a legal Traversal, unless you are very careful not to invalidate the predicate on the target.

Note: This is also not a legal Prism, unless you are very careful not to inject a value that matches the predicate.

As a counter example, consider that given evens = filtered even the second Traversal law is violated:

over evens succ . over evens succ /= over evens (succ . succ)


So, in order for this to qualify as a legal Traversal you can only use it for actions that preserve the result of the predicate!

>>> [1..10]^..folded.filtered even
[2,4,6,8,10]


This will preserve an index if it is present.

folding :: Foldable f => (s -> f a) -> Fold s a #

Obtain a Fold by lifting an operation that returns a Foldable result.

This can be useful to lift operations from Data.List and elsewhere into a Fold.

>>> [1,2,3,4]^..folding tail
[2,3,4]


_Just :: Prism (Maybe a) (Maybe b) a b #

This Prism provides a Traversal for tweaking the target of the value of Just in a Maybe.

>>> over _Just (+1) (Just 2)
Just 3


Unlike traverse this is a Prism, and so you can use it to inject as well:

>>> _Just # 5
Just 5

>>> 5^.re _Just
Just 5


Interestingly,

m ^? _Just ≡ m

>>> Just x ^? _Just
Just x

>>> Nothing ^? _Just
Nothing


prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b #

Build a Prism.

Either t a is used instead of Maybe a to permit the types of s and t to differ.

un :: (Profunctor p, Bifunctor p, Functor f) => Getting a s a -> Optic' p f a s #

Turn a Getter around to get a Review

un = unto . view
unto = un . to

>>> un (to length) # [1,2,3]
3


view :: MonadReader s m => Getting a s a -> m a #

View the value pointed to by a Getter, Iso or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal value.

view . to ≡ id

>>> view (to f) a
f a

>>> view _2 (1,"hello")
"hello"

>>> view (to succ) 5
6

>>> view (_2._1) ("hello",("world","!!!"))
"world"


As view is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold, It may be useful to think of it as having one of these more restricted signatures:

view ::             Getter s a     -> s -> a
view :: Monoid m => Fold s m       -> s -> m
view ::             Iso' s a       -> s -> a
view ::             Lens' s a      -> s -> a
view :: Monoid m => Traversal' s m -> s -> m


In a more general setting, such as when working with a Monad transformer stack you can use:

view :: MonadReader s m             => Getter s a     -> m a
view :: (MonadReader s m, Monoid a) => Fold s a       -> m a
view :: MonadReader s m             => Iso' s a       -> m a
view :: MonadReader s m             => Lens' s a      -> m a
view :: (MonadReader s m, Monoid a) => Traversal' s a -> m a


to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a #

Build an (index-preserving) Getter from an arbitrary Haskell function.

to f . to g ≡ to (g . f)

a ^. to f ≡ f a

>>> a ^.to f
f a

>>> ("hello","world")^.to snd
"world"

>>> 5^.to succ
6

>>> (0, -5)^._2.to abs
5

to :: (s -> a) -> IndexPreservingGetter s a


_1 :: Field1 s t a b => Lens s t a b #

Access the 1st field of a tuple (and possibly change its type).

>>> (1,2)^._1
1

>>> _1 .~ "hello" $(1,2) ("hello",2)  >>> (1,2) & _1 .~ "hello" ("hello",2)  >>> _1 putStrLn ("hello","world") hello ((),"world")  This can also be used on larger tuples as well: >>> (1,2,3,4,5) & _1 +~ 41 (42,2,3,4,5)  _1 :: Lens (a,b) (a',b) a a' _1 :: Lens (a,b,c) (a',b,c) a a' _1 :: Lens (a,b,c,d) (a',b,c,d) a a' ... _1 :: Lens (a,b,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'  _2 :: Field2 s t a b => Lens s t a b # Access the 2nd field of a tuple. >>> _2 .~ "hello"$ (1,(),3,4)
(1,"hello",3,4)

>>> (1,2,3,4) & _2 *~ 3
(1,6,3,4)

>>> _2 print (1,2)
2
(1,())

anyOf _2 :: (s -> Bool) -> (a, s) -> Bool
traverse . _2 :: (Applicative f, Traversable t) => (a -> f b) -> t (s, a) -> f (t (s, b))
foldMapOf (traverse . _2) :: (Traversable t, Monoid m) => (s -> m) -> t (b, s) -> m


lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b #

Build a Lens from a getter and a setter.

lens :: Functor f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t

>>> s ^. lens getter setter
getter s

>>> s & lens getter setter .~ b
setter s b

>>> s & lens getter setter %~ f
setter s (f (getter s))

lens :: (s -> a) -> (s -> a -> s) -> Lens' s a


sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Optical p q f s t a b #

Build a Setter, IndexedSetter or IndexPreservingSetter depending on your choice of Profunctor.

sets :: ((a -> b) -> s -> t) -> Setter s t a b


(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

>>> 5 & (+1) & show
"6"


Since: base-4.8.0.0

(<&>) :: 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 (^?) :: s -> Getting (First a) s a -> Maybe a infixl 8 # Perform a safe head of a Fold or Traversal or retrieve Just the result from a Getter or Lens. When using a Traversal as a partial Lens, or a Fold as a partial Getter this can be a convenient way to extract the optional value. Note: if you get stack overflows due to this, you may want to use firstOf instead, which can deal more gracefully with heavily left-biased trees. >>> Left 4 ^?_Left Just 4  >>> Right 4 ^?_Left Nothing  >>> "world" ^? ix 3 Just 'l'  >>> "world" ^? ix 20 Nothing  (^?) ≡ flip preview  (^?) :: s -> Getter s a -> Maybe a (^?) :: s -> Fold s a -> Maybe a (^?) :: s -> Lens' s a -> Maybe a (^?) :: s -> Iso' s a -> Maybe a (^?) :: s -> Traversal' s a -> Maybe a  (#) :: AReview t b -> b -> t infixr 8 # An infix alias for review. unto f # x ≡ f x l # x ≡ x ^. re l  This is commonly used when using a Prism as a smart constructor. >>> _Left # 4 Left 4  But it can be used for any Prism >>> base 16 # 123 "7b"  (#) :: Iso' s a -> a -> s (#) :: Prism' s a -> a -> s (#) :: Review s a -> a -> s (#) :: Equality' s a -> a -> s  (^.) :: s -> Getting a s a -> a infixl 8 # View the value pointed to by a Getter or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal values. This is the same operation as view with the arguments flipped. The fixity and semantics are such that subsequent field accesses can be performed with (.). >>> (a,b)^._2 b  >>> ("hello","world")^._2 "world"  >>> import Data.Complex >>> ((0, 1 :+ 2), 3)^._1._2.to magnitude 2.23606797749979  (^.) :: s -> Getter s a -> a (^.) :: Monoid m => s -> Fold s m -> m (^.) :: s -> Iso' s a -> a (^.) :: s -> Lens' s a -> a (^.) :: Monoid m => s -> Traversal' s m -> m  (<>~) :: Monoid a => ASetter s t a a -> a -> s -> t infixr 4 # Modify the target of a monoidally valued by mappending another value. >>> (Sum a,b) & _1 <>~ Sum c (Sum {getSum = a + c},b)  >>> (Sum a,Sum b) & both <>~ Sum c (Sum {getSum = a + c},Sum {getSum = b + c})  >>> both <>~ "!!!"$ ("hello","world")
("hello!!!","world!!!")

(<>~) :: Monoid a => Setter s t a a    -> a -> s -> t
(<>~) :: Monoid a => Iso s t a a       -> a -> s -> t
(<>~) :: Monoid a => Lens s t a a      -> a -> s -> t
(<>~) :: Monoid a => Traversal s t a a -> a -> s -> t


(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 #

Set the target of a Lens, Traversal or Setter to Just a value.

l ?~ t ≡ set l (Just t)

>>> Nothing & id ?~ a
Just a

>>> Map.empty & at 3 ?~ x
fromList [(3,x)]

(?~) :: Setter s t a (Maybe b)    -> b -> s -> t
(?~) :: Iso s t a (Maybe b)       -> b -> s -> t
(?~) :: Lens s t a (Maybe b)      -> b -> s -> t
(?~) :: Traversal s t a (Maybe b) -> b -> s -> t


(.~) :: ASetter s t a b -> b -> s -> t infixr 4 #

Replace the target of a Lens or all of the targets of a Setter or Traversal with a constant value.

This is an infix version of set, provided for consistency with (.=).

f <$ a ≡ mapped .~ f $ a

>>> (a,b,c,d) & _4 .~ e
(a,b,c,e)

>>> (42,"world") & _1 .~ "hello"
("hello","world")

>>> (a,b) & both .~ c
(c,c)

(.~) :: Setter s t a b    -> b -> s -> t
(.~) :: Iso s t a b       -> b -> s -> t
(.~) :: Lens s t a b      -> b -> s -> t
(.~) :: Traversal s t a b -> b -> s -> t


(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #

Modifies the target of a Lens or all of the targets of a Setter or Traversal with a user supplied function.

This is an infix version of over.

fmap f ≡ mapped %~ f
fmapDefault f ≡ traverse %~ f

>>> (a,b,c) & _3 %~ f
(a,b,f c)

>>> (a,b) & both %~ f
(f a,f b)

>>> _2 %~ length $(1,"hello") (1,5)  >>> traverse %~ f$ [a,b,c]
[f a,f b,f c]

>>> traverse %~ even $[1,2,3] [False,True,False]  >>> traverse.traverse %~ length$ [["hello","world"],["!!!"]]
[[5,5],[3]]

(%~) :: Setter s t a b    -> (a -> b) -> s -> t
(%~) :: Iso s t a b       -> (a -> b) -> s -> t
(%~) :: Lens s t a b      -> (a -> b) -> s -> t
(%~) :: Traversal s t a b -> (a -> b) -> s -> t