| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Prelude
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
- (&) :: a -> (a -> b) -> b
- (.) :: (b -> c) -> (a -> b) -> a -> c
- (%) :: (Additive - 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
- (#) :: (Additive - 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
- view :: MonadReader s m => AView s a -> m a
- (^.) :: s -> AView s a -> a
- iview :: MonadReader s m => (Additive - Monoid) i => AIxview i s a -> m (Maybe i, a)
- (^%) :: (Additive - Monoid) i => s -> AIxview i s a -> (Maybe i, a)
- review :: MonadReader b m => AReview t b -> m t
- (#^) :: AReview t b -> b -> t
- set :: Optic (->) s t a b -> b -> s -> t
- (.~) :: Optic (->) s t a b -> b -> s -> t
- iset :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> b) -> s -> t
- (%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> b) -> s -> t
- kset :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t
- (#~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t
- over :: Optic (->) s t a b -> (a -> b) -> s -> t
- (..~) :: Optic (->) s t a b -> (a -> b) -> s -> t
- iover :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
- (%%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
- kover :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
- (##~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
- (<>~) :: Semigroup a => Optic (->) s t a a -> a -> s -> t
- preview :: MonadReader s m => AOption a s a -> m (Maybe a)
- (^?) :: s -> AOption a s a -> Maybe a
- is :: AOption a s a -> s -> Bool
- isnt :: AOption a s a -> s -> Bool
- matches :: AAffine s t a b -> s -> t + a
- lists :: AFold (Endo [a]) s a -> s -> [a]
- (^..) :: s -> AFold (Endo [a]) s a -> [a]
- ilists :: (Additive - Monoid) i => AIxfold (Endo [(i, a)]) i s a -> s -> [(i, a)]
- ilistsFrom :: AIxfold (Endo [(i, a)]) i s a -> i -> s -> [(i, a)]
- (^%%) :: (Additive - Monoid) i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)]
- folds :: Monoid a => AFold a s a -> s -> a
- foldsa :: Applicative f => Monoid (f a) => AFold (f a) s a -> s -> f a
- foldsr :: AFold (Endo r) s a -> (a -> r -> r) -> r -> s -> r
- ifoldsr :: (Additive - Monoid) i => AIxfold (Endo r) i s a -> (i -> a -> r -> r) -> r -> s -> r
- ifoldsrFrom :: AIxfold (Endo r) i s a -> (i -> a -> r -> r) -> i -> r -> s -> r
- foldsl :: AFold ((Endo - Dual) r) s a -> (r -> a -> r) -> r -> s -> r
- ifoldsl :: (Additive - Monoid) i => AIxfold ((Endo - Dual) r) i s a -> (i -> r -> a -> r) -> r -> s -> r
- ifoldslFrom :: AIxfold ((Endo - Dual) r) i s a -> (i -> r -> a -> r) -> i -> r -> s -> r
- foldsr' :: AFold ((Endo - Dual) (Endo r)) s a -> (a -> r -> r) -> r -> s -> r
- ifoldsr' :: (Additive - Monoid) i => AIxfold ((Endo - Dual) (r -> r)) i s a -> (i -> a -> r -> r) -> r -> s -> r
- foldsl' :: AFold ((Endo - Endo) r) s a -> (r -> a -> r) -> r -> s -> r
- ifoldsl' :: (Additive - Monoid) i => AIxfold (Endo (r -> r)) i s a -> (i -> r -> a -> r) -> r -> s -> r
- foldsrM :: Monad m => AFold ((Endo - Dual) (r -> m r)) s a -> (a -> r -> m r) -> r -> s -> m r
- ifoldsrM :: (Additive - Monoid) i => Monad m => AIxfold ((Endo - Dual) (r -> m r)) i s a -> (i -> a -> r -> m r) -> r -> s -> m r
- foldslM :: Monad m => AFold (Endo (r -> m r)) s a -> (r -> a -> m r) -> r -> s -> m r
- ifoldslM :: (Additive - Monoid) i => Monad m => AIxfold (Endo (r -> m r)) i s a -> (i -> r -> a -> m r) -> r -> s -> m r
- traverses_ :: Applicative f => AFold (Endo (f ())) s a -> (a -> f r) -> s -> f ()
- itraverses_ :: (Additive - Monoid) i => Applicative f => AIxfold (Endo (f ())) i s a -> (i -> a -> f r) -> s -> f ()
- sums :: (Additive - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a
- multiplies :: (Multiplicative - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a
- asums :: Alternative f => AFold ((Endo - Endo) (f a)) s (f a) -> s -> f a
- concats :: AFold [r] s a -> (a -> [r]) -> s -> [r]
- iconcats :: (Additive - Monoid) i => AIxfold [r] i s a -> (i -> a -> [r]) -> s -> [r]
- endo :: AFold (Endo (a -> a)) s (a -> a) -> s -> a -> a
- endoM :: Monad m => AFold (Endo (a -> m a)) s (a -> m a) -> s -> a -> m a
- finds :: AFold ((Maybe - Endo) a) s a -> (a -> Bool) -> s -> Maybe a
- ifinds :: (Additive - Monoid) i => AIxfold ((Maybe - Endo) (i, a)) i s a -> (i -> a -> Bool) -> s -> Maybe (i, a)
- has :: AFold (Additive Bool) s a -> s -> Bool
- hasnt :: AFold (Multiplicative Bool) s a -> s -> Bool
- elem :: Eq a => AFold (Additive Bool) s a -> a -> s -> Bool
- pelem :: Prd a => AFold (Additive Bool) s a -> a -> s -> Bool
- joins :: Lattice a => AFold ((Endo - Endo) a) s a -> a -> s -> a
- joins' :: Lattice a => Minimal a => AFold ((Endo - Endo) a) s a -> s -> a
- meets :: Lattice a => AFold ((Endo - Endo) a) s a -> a -> s -> a
- meets' :: Lattice a => Maximal a => AFold ((Endo - Endo) a) s a -> s -> a
- mins :: Ord a => AFold ((Endo - Endo) a) s a -> a -> s -> a
- maxes :: Ord a => AFold ((Endo - Endo) a) s a -> a -> s -> a
Documentation
Composition
(%) :: (Additive - 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 #
(#) :: (Additive - 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 ..
View operators
view :: MonadReader s m => AView s a -> m a Source #
(^.) :: s -> AView s a -> a infixl 8 Source #
View the focus of an optic.
Fixity and semantics are such that subsequent field accesses can be
performed with (.).
>>>("hello","world") ^. second'"world"
>>>5 ^. to succ6
>>>import Data.Complex>>>((0, 1 :+ 2), 3) ^. first' . second' . to magnitude2.23606797749979
iview :: MonadReader s m => (Additive - Monoid) i => AIxview i s a -> m (Maybe i, a) Source #
A prefix alias for ^%.
>>>iview ifirst ("foo", 42)(Just (),"foo")
(^%) :: (Additive - Monoid) i => s -> AIxview i s a -> (Maybe i, a) infixl 8 Source #
View the focus of an indexed optic along with its index.
>>>("foo", 42) ^% ifirst(Just (),"foo")
review :: MonadReader b m => AReview t b -> m t Source #
Setter operators
(.~) :: Optic (->) s t a b -> b -> s -> t infixr 4 Source #
Set all referenced fields to the given value.
(#~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t infixr 4 Source #
Set the focus of a coindexed optic.
See also %~.
(..~) :: Optic (->) s t a b -> (a -> b) -> s -> t infixr 4 Source #
Map over an optic.
>>>Just 1 & just ..~ (+1)Just 2
>>>Nothing & just ..~ (+1)Nothing
>>>[1,2,3] & fmapped ..~ (*10)[10,20,30]
>>>(1,2) & first' ..~ (+1)(2,2)
>>>(10,20) & first' ..~ show("10",20)
iover :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t Source #
Prefix alias of %%~.
>>>iover (iat 1) (+) [1,2,3 :: Int][1,3,3]>>>iover (iat 5) (+) [1,2,3 :: Int][1,2,3]
(%%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t infixr 4 Source #
Map over an indexed optic.
See also ##~.
kover :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t Source #
Prefix alias of ##~.
(<>~) :: Semigroup a => Optic (->) s t a a -> a -> s -> t infixr 4 Source #
Modify the target by adding another value.
>>>both <>~ "!" $ ("bar","baz")("bar!","baz!")
Fold operators
(^?) :: s -> AOption a s a -> Maybe a infixl 8 Source #
An infix alias for 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 ^? left'Just 4>>>Right 4 ^? left'Nothing
is :: AOption a s a -> s -> Bool Source #
Check whether the optic is matched.
>>>is just NothingFalse
isnt :: AOption a s a -> s -> Bool Source #
Check whether the optic isn't matched.
>>>isnt just NothingTrue
matches :: AAffine 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
(^..) :: s -> AFold (Endo [a]) s a -> [a] infixl 8 Source #
Infix alias of lists.
toListxs ≡ xs^..folding(^..) ≡fliplists
>>>[[1,2], [3 :: Int64]] ^.. id[[[1,2],[3]]]>>>[[1,2], [3 :: Int64]] ^.. traversed[[1,2],[3]]>>>[[1,2], [3 :: Int64]] ^.. 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]
ilistsFrom :: AIxfold (Endo [(i, a)]) i s a -> i -> s -> [(i, a)] Source #
Collect the foci of an indexed optic into a list of index-value pairs.
This is only for use with the few indexed optics that don't ignore their
output index. You most likely want to use ilists.
(^%%) :: (Additive - Monoid) i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)] infixl 8 Source #
Infix version of ilists.
foldsa :: Applicative f => Monoid (f a) => AFold (f a) s a -> s -> f a Source #
TODO: Document
foldsa :: Fold s a -> s -> [a] foldsa :: Applicative f => Setter s t a b -> s -> f a
foldsr :: AFold (Endo r) s a -> (a -> r -> r) -> r -> s -> r Source #
Right fold over an optic.
>>>foldsr folded (+) 0 [1..5::Int64]15
ifoldsr :: (Additive - Monoid) i => AIxfold (Endo r) i s a -> (i -> a -> r -> r) -> r -> s -> r Source #
ifoldsrFrom :: AIxfold (Endo r) i s a -> (i -> a -> r -> r) -> i -> r -> s -> r Source #
Indexed right fold over an indexed optic, using an initial index value.
This is only for use with the few indexed optics that don't ignore their
output index. You most likely want to use ifoldsr.
foldsl :: AFold ((Endo - Dual) r) s a -> (r -> a -> r) -> r -> s -> r Source #
Left fold over an optic.
ifoldsl :: (Additive - Monoid) i => AIxfold ((Endo - Dual) r) i s a -> (i -> r -> a -> r) -> r -> s -> r Source #
ifoldslFrom :: AIxfold ((Endo - Dual) r) i s a -> (i -> r -> a -> r) -> i -> r -> s -> r Source #
Left fold over an indexed optic, using an initial index value.
This is only for use with the few indexed optics that don't ignore their
output index. You most likely want to use ifoldsl.
foldsr' :: AFold ((Endo - Dual) (Endo r)) s a -> (a -> r -> r) -> r -> s -> r Source #
Strict right fold over an optic.
ifoldsr' :: (Additive - Monoid) i => AIxfold ((Endo - Dual) (r -> r)) i s a -> (i -> a -> r -> r) -> r -> s -> r Source #
foldsl' :: AFold ((Endo - Endo) r) s a -> (r -> a -> r) -> r -> s -> r Source #
Strict left fold over an optic.
foldl'≡foldsl'folding
foldsl'::Iso's a -> (c -> a -> c) -> c -> s -> cfoldsl'::Lens's a -> (c -> a -> c) -> c -> s -> cfoldsl'::Views a -> (c -> a -> c) -> c -> s -> cfoldsl'::Folds a -> (c -> a -> c) -> c -> s -> cfoldsl'::Traversal's a -> (c -> a -> c) -> c -> s -> cfoldsl'::Affine's a -> (c -> a -> c) -> c -> s -> c
ifoldsl' :: (Additive - Monoid) i => AIxfold (Endo (r -> r)) i s a -> (i -> r -> a -> r) -> r -> s -> r Source #
foldsrM :: Monad m => AFold ((Endo - Dual) (r -> m r)) s a -> (a -> r -> m r) -> r -> s -> m r Source #
Monadic right fold over an optic.
ifoldsrM :: (Additive - Monoid) i => Monad m => AIxfold ((Endo - Dual) (r -> m r)) i s a -> (i -> a -> r -> m r) -> r -> s -> m r Source #
foldslM :: Monad m => AFold (Endo (r -> m r)) s a -> (r -> a -> m r) -> r -> s -> m r Source #
Monadic left fold over an optic.
ifoldslM :: (Additive - Monoid) i => Monad m => AIxfold (Endo (r -> m r)) i s a -> (i -> r -> a -> m r) -> r -> s -> m r Source #
traverses_ :: Applicative f => AFold (Endo (f ())) s a -> (a -> f r) -> s -> f () Source #
Applicative fold over an optic.
>>>traverses_ both putStrLn ("hello","world")hello world
traverse_≡traverses_folded
itraverses_ :: (Additive - Monoid) i => Applicative f => AIxfold (Endo (f ())) i s a -> (i -> a -> f r) -> s -> f () Source #
Applicative fold over an indexed optic.
sums :: (Additive - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a Source #
The sum of a collection.
multiplies :: (Multiplicative - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a Source #
The product of a collection.
ifinds :: (Additive - Monoid) i => AIxfold ((Maybe - Endo) (i, a)) i s a -> (i -> a -> Bool) -> s -> Maybe (i, a) Source #
Find the first focus of an indexed optic that satisfies a predicate, if one exists.
has :: AFold (Additive Bool) s a -> s -> Bool Source #
Determine whether an optic has at least one focus.
hasnt :: AFold (Multiplicative Bool) s a -> s -> Bool Source #
Determine whether an optic does not have a focus.
elem :: Eq a => AFold (Additive Bool) s a -> a -> s -> Bool Source #
Determine whether the targets of a Fold contain a given element.
pelem :: Prd a => AFold (Additive Bool) s a -> a -> s -> Bool Source #
Determine whether the foci of an optic contain an element equivalent to a given element.
joins :: Lattice a => AFold ((Endo - Endo) a) s a -> a -> s -> a Source #
Compute the join of the foci of an optic.
joins' :: Lattice a => Minimal a => AFold ((Endo - Endo) a) s a -> s -> a Source #
Compute the join of the foci of an optic including a least element.
meets :: Lattice a => AFold ((Endo - Endo) a) s a -> a -> s -> a Source #
Compute the meet of the foci of an optic .
meets' :: Lattice a => Maximal a => AFold ((Endo - Endo) a) s a -> s -> a Source #
Compute the meet of the foci of an optic including a greatest element.