Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Fold s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => Optic' p s a
- type Ixfold i s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => IndexedOptic' p i s a
- fold_ :: Foldable f => (s -> f a) -> Fold s a
- folding :: Traversable f => (s -> a) -> Fold (f s) a
- foldVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Fold s a
- ifoldVl :: (forall f. Applicative f => (i -> a -> f b) -> s -> f t) -> Ixfold i s a
- toFold :: AView s a -> Fold s a
- afold :: ((a -> r) -> s -> r) -> APrimView r s t a b
- aifold :: ((i -> a -> r) -> s -> r) -> AIxfold r i s a
- type Fold1 s a = forall p. (Strong p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => Optic' p s a
- type Ixfold1 i s a = forall p. (Strong p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => IndexedOptic' p i s a
- fold1_ :: Foldable1 f => (s -> f a) -> Fold1 s a
- folding1 :: Traversable1 f => (s -> a) -> Fold1 (f s) a
- fold1Vl :: (forall f. Apply f => (a -> f b) -> s -> f t) -> Fold1 s a
- toFold1 :: AView s a -> Fold1 s a
- afold1 :: ((a -> r) -> s -> r) -> APrimView r s t a b
- folded :: Traversable f => Fold (f a) a
- folded_ :: Foldable f => Fold (f a) a
- folded1 :: Traversable1 f => Fold1 (f a) a
- folded1_ :: Foldable1 f => Fold1 (f a) a
- ifoldedRep :: Representable f => Traversable f => Ixfold (Rep f) (f a) a
- unital :: Foldable f => Foldable g => Monoid r => Semiring r => AFold r (f (g a)) a
- nonunital :: Foldable f => Foldable1 g => Monoid r => Semiring r => AFold r (f (g a)) a
- presemiring :: Foldable1 f => Foldable1 g => Semiring r => AFold1 r (f (g a)) a
- summed :: Foldable f => Monoid r => AFold r (f a) a
- summed1 :: Foldable1 f => Semigroup r => AFold1 r (f a) a
- multiplied :: Foldable f => Monoid r => Semiring r => AFold r (f a) a
- multiplied1 :: Foldable1 f => Semiring r => AFold1 r (f a) a
- withFold :: Monoid r => APrimView r s t a b -> (a -> r) -> s -> r
- withIxfold :: Monoid r => AIxfold r i s a -> (i -> a -> r) -> i -> s -> r
- withFold1 :: Semigroup r => APrimView r s t a b -> (a -> r) -> s -> r
- withIxfold1 :: Semigroup r => AIxfold1 r i s a -> (i -> a -> r) -> i -> s -> r
- lists :: AFold (Endo [a]) s a -> s -> [a]
- (^..) :: s -> AFold (Endo [a]) s a -> [a]
- ilists :: Monoid i => AIxfold (Endo [(i, a)]) i s a -> s -> [(i, a)]
- ilistsFrom :: AIxfold (Endo [(i, a)]) i s a -> i -> s -> [(i, a)]
- (^%%) :: Monoid i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)]
- nelists :: AFold1 (Nedl a) s a -> s -> NonEmpty a
- folds :: Monoid a => AFold a s a -> s -> a
- ifolds :: Monoid i => Monoid a => AIxfold (i, a) i s a -> s -> (i, a)
- folds1 :: Semigroup a => AFold1 a s a -> s -> a
- foldsa :: Applicative f => Monoid (f a) => AFold (f a) s a -> s -> f a
- foldsp :: Monoid r => Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r
- folds1p :: Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r
- foldsr :: AFold (Endo r) s a -> (a -> r -> r) -> r -> s -> r
- ifoldsr :: 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 (Dual (Endo r)) s a -> (r -> a -> r) -> r -> s -> r
- ifoldsl :: Monoid i => AIxfold (Dual (Endo r)) i s a -> (i -> r -> a -> r) -> r -> s -> r
- ifoldslFrom :: AIxfold (Dual (Endo r)) i s a -> (i -> r -> a -> r) -> i -> r -> s -> r
- foldsr' :: AFold (Dual (Endo (Endo r))) s a -> (a -> r -> r) -> r -> s -> r
- ifoldsr' :: Monoid i => AIxfold (Dual (Endo (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' :: Monoid i => AIxfold (Endo (r -> r)) i s a -> (i -> r -> a -> r) -> r -> s -> r
- foldsrM :: Monad m => AFold (Dual (Endo (r -> m r))) s a -> (a -> r -> m r) -> r -> s -> m r
- ifoldsrM :: Monoid i => Monad m => AIxfold (Dual (Endo (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 :: 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_ :: Monoid i => Applicative f => AIxfold (Endo (f ())) i s a -> (i -> a -> f r) -> s -> f ()
- type All = Prod Bool
- type Any = Bool
- newtype Nedl a = Nedl {}
Fold & Ixfold
type Fold s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => Optic' p s a Source #
type Ixfold i s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => IndexedOptic' p i s a Source #
folding :: Traversable f => (s -> a) -> Fold (f s) a Source #
foldVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Fold s a Source #
ifoldVl :: (forall f. Applicative f => (i -> a -> f b) -> s -> f t) -> Ixfold i s a Source #
afold :: ((a -> r) -> s -> r) -> APrimView r s t a b Source #
TODO: Document
afold :: ((a -> r) -> s -> r) -> AFold r s a
Fold1 & Ixfold1
type Fold1 s a = forall p. (Strong p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => Optic' p s a Source #
type Ixfold1 i s a = forall p. (Strong p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => IndexedOptic' p i s a Source #
folding1 :: Traversable1 f => (s -> a) -> Fold1 (f s) a Source #
Obtain a Fold1
from a Traversable1
functor.
folding1
f ≡traversed1
.to
ffolding1
f ≡fold1Vl
traverse1
.to
f
afold1 :: ((a -> r) -> s -> r) -> APrimView r s t a b Source #
TODO: Document
afold1 :: ((a -> r) -> s -> r) -> AFold1 r s a
Optics
folded :: Traversable f => Fold (f a) a Source #
Obtain a Fold
from a Traversable
functor.
folded1 :: Traversable1 f => Fold1 (f a) a Source #
Obtain a Fold1
from a Traversable1
functor.
ifoldedRep :: Representable f => Traversable f => Ixfold (Rep f) (f a) a Source #
Obtain an Ixfold
from a Representable
functor.
unital :: Foldable f => Foldable g => Monoid r => Semiring r => AFold r (f (g a)) a Source #
Expression in a unital semiring
unital
≡summed
.multiplied
>>>
folds unital [[1,2], [3,4 :: Int]]
14
For semirings without a multiplicative unit this is
equivalent to const mempty
:
>>>
folds unital $ (fmap . fmap) Just [[1,2], [3,4 :: Int]]
Just 0
In this situation you most likely want to use nonunital
.
nonunital :: Foldable f => Foldable1 g => Monoid r => Semiring r => AFold r (f (g a)) a Source #
Expression in a semiring expression with no multiplicative unit.
nonunital
≡summed
.multiplied1
>>>
folds1 nonunital $ (fmap . fmap) Just [1 :| [2], 3 :| [4 :: Int]]
Just 14
presemiring :: Foldable1 f => Foldable1 g => Semiring r => AFold1 r (f (g a)) a Source #
Expression in a semiring with no additive or multiplicative unit.
presemiring
≡summed1
.multiplied1
summed :: Foldable f => Monoid r => AFold r (f a) a Source #
Monoidal sum of a foldable collection.
>>>
1 <> 2 <> 3 <> 4 :: Int
10>>>
folds summed [1,2,3,4 :: Int]
10
summed
and multiplied
compose just as they do in arithmetic:
>>>
1 >< 2 <> 3 >< 4 :: Int
14>>>
folds (summed . multiplied) [[1,2], [3,4 :: Int]]
14>>>
(1 <> 2) >< (3 <> 4) :: Int
21>>>
folds (multiplied . summed) [[1,2], [3,4 :: Int]]
21
summed1 :: Foldable1 f => Semigroup r => AFold1 r (f a) a Source #
Semigroup sum of a non-empty foldable collection.
>>>
1 <> 2 <> 3 <> 4 :: Int
10>>>
folds1 summed1 $ 1 :| [2,3,4 :: Int]
10
multiplied :: Foldable f => Monoid r => Semiring r => AFold r (f a) a Source #
Semiring product of a foldable collection.
>>>
1 >< 2 >< 3 >< 4 :: Int
24>>>
folds multiplied [1,2,3,4 :: Int]
24
For semirings without a multiplicative unit this is
equivalent to const mempty
:
>>>
folds multiplied $ fmap Just [1..(5 :: Int)]
Just 0
In this situation you most likely want to use multiplied1
.
multiplied1 :: Foldable1 f => Semiring r => AFold1 r (f a) a Source #
Semiring product of a non-empty foldable collection.
>>>
folds1 multiplied1 $ fmap Just (1 :| [2..(5 :: Int)])
Just 120
Primitive operators
withIxfold :: Monoid r => AIxfold r i s a -> (i -> a -> r) -> i -> s -> r Source #
Map an indexed optic to a monoid and combine the results.
Note that most indexed optics do not use their output index:
>>>
withIxfold itraversed const 100 [1..5]
10>>>
withIxfold itraversed const 100 []
0
withIxfold1 :: Semigroup r => AIxfold1 r i s a -> (i -> a -> r) -> i -> s -> r Source #
Map an indexed optic to a semigroup and combine the results.
>>>
:t flip withIxfold1 Map.singleton
flip withIxfold1 Map.singleton :: Ord i => AIxfold1 (Map i a) i s a -> i -> s -> Map i a
withIxfold1
::Semigroup
r =>AIxfold1
r s a -> (i -> a -> r) -> i -> s -> r
Operators
(^..) :: s -> AFold (Endo [a]) s a -> [a] infixl 8 Source #
Infix alias of lists
.
toList
xs ≡ xs^..
folding
(^..
) ≡flip
lists
>>>
[[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 ->View
s a -> a :: s ->Fold
s 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
.
(^%%) :: Monoid i => s -> AIxfold (Endo [(i, a)]) i s a -> [(i, a)] infixl 8 Source #
Infix version of ilists
.
nelists :: AFold1 (Nedl a) s a -> s -> NonEmpty a Source #
Extract a NonEmpty
of the foci of an optic.
>>>
nelists bitraversed1 ('h' :| "ello", 'w' :| "orld")
('h' :| "ello") :| ['w' :| "orld"]
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
foldsp :: Monoid r => Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r Source #
Compute the semiring product of the foci of an optic.
For semirings without a multiplicative unit this is equivalent to const mempty
:
>>>
foldsp folded Just [1..(5 :: Int)]
Just 0
In this situation you most likely want to use folds1p
.
folds1p :: Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r Source #
Compute the semiring product of the foci of an optic.
foldsr :: AFold (Endo r) s a -> (a -> r -> r) -> r -> s -> r Source #
Right fold over an optic.
>>>
foldsr folded (<>) 0 [1..5::Int]
15
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 (Dual (Endo r)) s a -> (r -> a -> r) -> r -> s -> r Source #
Left fold over an optic.
ifoldsl :: Monoid i => AIxfold (Dual (Endo r)) i s a -> (i -> r -> a -> r) -> r -> s -> r Source #
Left fold over an indexed optic.
ifoldslFrom :: AIxfold (Dual (Endo 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 (Dual (Endo (Endo r))) s a -> (a -> r -> r) -> r -> s -> r Source #
Strict right fold over an optic.
ifoldsr' :: Monoid i => AIxfold (Dual (Endo (r -> r))) i s a -> (i -> a -> r -> r) -> r -> s -> r Source #
Strict right fold over an indexed optic.
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'
::View
s a -> (c -> a -> c) -> c -> s -> cfoldsl'
::Fold
s 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' :: Monoid i => AIxfold (Endo (r -> r)) i s a -> (i -> r -> a -> r) -> r -> s -> r Source #
Strict left fold over an indexed optic.
foldsrM :: Monad m => AFold (Dual (Endo (r -> m r))) s a -> (a -> r -> m r) -> r -> s -> m r Source #
Monadic right fold over an optic.
ifoldsrM :: Monoid i => Monad m => AIxfold (Dual (Endo (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 :: 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_ :: Monoid i => Applicative f => AIxfold (Endo (f ())) i s a -> (i -> a -> f r) -> s -> f () Source #
Applicative fold over an indexed optic.