| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Operator
Synopsis
- re :: Optic (Re p a b) s t a b -> Optic p b a t s
- invert :: AIso s t a b -> Iso b a t s
- view :: MonadReader s m => AView s a -> m a
- review :: MonadReader b m => AReview t b -> m t
- preview :: MonadReader s m => AFold0 a s a -> m (Maybe a)
- over :: ASetter s t a b -> (a -> b) -> s -> t
- under :: AResetter s t a b -> (a -> b) -> s -> t
- set :: ASetter s t a b -> b -> s -> t
- reset :: AResetter s t a b -> b -> s -> t
- is :: ATraversal0 s t a b -> s -> Bool
- matches :: ATraversal0 s t a b -> s -> t + a
- (&) :: a -> (a -> b) -> b
- (%) :: Semigroup i => Representable p => IndexedOptic p i b1 b2 a1 a2 -> IndexedOptic p i c1 c2 b1 b2 -> IndexedOptic p i c1 c2 a1 a2
- (#) :: Semigroup k => Corepresentable p => CoindexedOptic p k b1 b2 a1 a2 -> CoindexedOptic p k c1 c2 b1 b2 -> CoindexedOptic p k c1 c2 a1 a2
- (^.) :: s -> AView s a -> a
- (^%) :: Monoid i => s -> AIxview a i s a -> (Maybe i, a)
- (#^) :: AReview t b -> b -> t
- (^?) :: s -> AFold0 a s a -> Maybe a
- (^..) :: s -> AFold (Endo [a]) s a -> [a]
- (^%%) :: Monoid i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)]
- (.~) :: ASetter s t a b -> b -> s -> t
- (%~) :: Monoid i => AIxsetter i s t a b -> (i -> b) -> s -> t
- (..~) :: ASetter s t a b -> (a -> b) -> s -> t
- (%%~) :: Monoid i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
- (/~) :: AResetter s t a b -> b -> s -> t
- (#~) :: Monoid k => ACxsetter k s t a b -> (k -> b) -> s -> t
- (//~) :: AResetter s t a b -> (a -> b) -> s -> t
- (##~) :: Monoid k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
- (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
- (<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t
- (><~) :: Semiring a => ASetter s t a a -> a -> s -> t
- module Data.Profunctor.Extra
Documentation
view :: MonadReader s m => AView s a -> m a Source #
review :: MonadReader b m => AReview t b -> m t Source #
over :: ASetter s t a b -> (a -> b) -> s -> t Source #
Extract a SEC from a Setter.
Used to modify the target of a Lens or all the targets of a Setter
or Traversal.
overoid≡idovero f.overo g ≡overo (f.g)setter.over≡idover.setter≡id
>>>over fmapped (+1) (Just 1)Just 2
>>>over fmapped (*10) [1,2,3][10,20,30]
>>>over t21 (+1) (1,2)(2,2)
>>>over t21 show (10,20)("10",20)
over :: Setter s t a b -> (a -> r) -> s -> r over :: Monoid r => Fold s t a b -> (a -> r) -> s -> r
under :: AResetter s t a b -> (a -> b) -> s -> t Source #
Extract a SEC from a Resetter.
underoid≡idundero f.undero g ≡undero (f.g)resetter.under≡idunder.resetter≡id
Note that under (more properly co-over) is distinct from reover:
>>>:t under $ wrapped @(Identity Int)under $ wrapped @(Identity Int) :: (Int -> Int) -> Identity Int -> Identity Int>>>:t over $ wrapped @(Identity Int)over $ wrapped @(Identity Int) :: (Int -> Int) -> Identity Int -> Identity Int>>>:t over . re $ wrapped @(Identity Int)over . re $ wrapped @(Identity Int) :: (Identity Int -> Identity Int) -> Int -> Int>>>:t reover $ wrapped @(Identity Int)reover $ wrapped @(Identity Int) :: (Identity Int -> Identity Int) -> Int -> Int
Compare to the lens-family version.
is :: ATraversal0 s t a b -> s -> Bool Source #
Check whether the optic is matchesed.
>>>is just NothingFalse
matches :: ATraversal0 s t a b -> s -> t + a Source #
Test whether the optic matches or not.
>>>matches just (Just 2)Right 2
>>>matches just (Nothing :: Maybe Int) :: Either (Maybe Bool) IntLeft Nothing
(%) :: Semigroup i => Representable p => IndexedOptic p i b1 b2 a1 a2 -> IndexedOptic p i c1 c2 b1 b2 -> IndexedOptic p i c1 c2 a1 a2 infixr 8 Source #
Compose two indexed traversals, combining indices.
Its precedence is one lower than that of function composition, which allows . to be nested in %.
If you only need the final index then use .:
>>>ixlists (ixtraversed . ixtraversed) foobar[(0,"foo"),(1,"bar"),(0,"baz"),(1,"bip")]
>>>ixlistsFrom (ixlast ixtraversed % ixlast ixtraversed) (Last 0) foobar & fmapped . t21 ..~ getLast[(0,"foo"),(1,"bar"),(0,"baz"),(1,"bip")]
>>>ixlists (ixtraversed . ixtraversed) exercises[("crunches",25),("handstands",5),("crunches",20),("pushups",10),("handstands",3),("pushups",15)]
>>>ixlists (ixtraversed % ixtraversed) exercises[("Fridaycrunches",25),("Fridayhandstands",5),("Mondaycrunches",20),("Mondaypushups",10),("Wednesdayhandstands",3),("Wednesdaypushups",15)]
(#) :: Semigroup k => Corepresentable p => CoindexedOptic p k b1 b2 a1 a2 -> CoindexedOptic p k c1 c2 b1 b2 -> CoindexedOptic p k c1 c2 a1 a2 infixr 8 Source #
Compose two coindexed traversals, combining indices.
Its precedence is one lower than that of function composition, which allows . to be nested in #.
If you only need the final index then use .
(^.) :: s -> AView s a -> a infixl 8 Source #
An infix alias for view. Dual to #.
Fixity and semantics are such that subsequent field accesses can be
performed with (.).
>>>("hello","world") ^. t22"world"
>>>import Data.Complex>>>((0, 1 :+ 2), 3) ^. t21 . t22 . to magnitude2.23606797749979
(^.) :: s ->Views a -> a (^.) ::Monoidm => s ->Folds m -> m (^.) :: s ->Iso's a -> a (^.) :: s ->Lens's a -> a (^.) :: s ->Coprism's a -> a (^.) ::Monoidm => s ->Traversal's m -> m
(^%) :: Monoid i => s -> AIxview a i s a -> (Maybe i, a) infixl 8 Source #
Bring the index and value of a indexed optic into the current environment as a pair.
This a flipped, infix variant of ixview and an indexed variant of ^..
The fixity and semantics are such that subsequent field accesses can be
performed with (.).
The result probably doesn't have much meaning when applied to an Ixfold.
(#^) :: AReview t b -> b -> t infixr 8 Source #
An infix variant of review. Dual to ^..
fromf #^ x ≡ f x o #^ x ≡ x^.reo
This is commonly used when using a Prism as a smart constructor.
>>>left #^ 4Left 4
(#^) ::Iso's a -> a -> s (#^) ::Prism's a -> a -> s (#^) ::Colens's a -> a -> s (#^) ::Reviews a -> a -> s (#^) ::Equality's a -> a -> s
(^?) :: s -> AFold0 a s a -> Maybe a infixl 8 Source #
An infix variant of preview'.
(^?) ≡flippreview'
Perform a safe head of a Fold or Traversal or retrieve Just
the result from a View or Lens.
When using a Traversal as a partial Lens, or a Fold as a partial
View this can be a convenient way to extract the optional value.
>>>Left 4 ^? leftJust 4
>>>Right 4 ^? leftNothing
(^..) :: s -> AFold (Endo [a]) s a -> [a] infixl 8 Source #
Infix version of lists.
toListxs ≡ xs^..folding(^..) ≡fliplists
>>>[[1,2], [3 :: Int]] ^.. id[[[1,2],[3]]]>>>[[1,2], [3 :: Int]] ^.. traversed[[1,2],[3]]>>>[[1,2], [3 :: Int]] ^.. traversed . traversed[1,2,3]
>>>(1,2) ^.. bitraversed[1,2]
(^..) :: s ->Views a -> a :: s ->Folds a -> a :: s ->Lens's a -> a :: s ->Iso's a -> a :: s ->Traversal's a -> a :: s ->Prism's a -> a :: s ->Affine's a -> [a]
(^%%) :: Monoid i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)] infixl 8 Source #
Infix version of ixlists.
(..~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 Source #
TODO: Document
>>>Nothing & just ..~ (+1)Nothing
(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 Source #
Set the target of a settable optic to Just a value.
l?~t ≡setl (Justt)
>>>Nothing & id ?~ 1Just 1
?~ can be used type-changily:
>>>('a', ('b', 'c')) & t22 . both ?~ 'x'('a',(Just 'x',Just 'x'))
(?~) ::Isos t a (Maybeb) -> b -> s -> t (?~) ::Lenss t a (Maybeb) -> b -> s -> t (?~) ::Grates t a (Maybeb) -> b -> s -> t (?~) ::Setters t a (Maybeb) -> b -> s -> t (?~) ::Traversals t a (Maybeb) -> b -> s -> t
(<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t infixr 4 Source #
Modify the target by adding another value.
>>>both <>~ False $ (False,True)(False,True)
>>>both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")
(<>~) ::Semigroupa =>Isos t a a -> a -> s -> t (<>~) ::Semigroupa =>Lenss t a a -> a -> s -> t (<>~) ::Semigroupa =>Grates t a a -> a -> s -> t (<>~) ::Semigroupa =>Setters t a a -> a -> s -> t (<>~) ::Semigroupa =>Traversals t a a -> a -> s -> t
(><~) :: Semiring a => ASetter s t a a -> a -> s -> t infixr 4 Source #
Modify the target by multiplying by another value.
>>>both ><~ False $ (False,True)(False,False)
(><~) ::Semiringa =>Isos t a a -> a -> s -> t (><~) ::Semiringa =>Lenss t a a -> a -> s -> t (><~) ::Semiringa =>Grates t a a -> a -> s -> t (><~) ::Semiringa =>Setters t a a -> a -> s -> t (><~) ::Semiringa =>Traversals t a a -> a -> s -> t
module Data.Profunctor.Extra