Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- type Fold0 s a = forall p. (Affine p, CoerceR p) => Optic' p s a
- fold0 :: (s -> Maybe a) -> Fold0 s a
- failing :: AFold0 a s a -> AFold0 a s a -> Fold0 s a
- toFold0 :: View s (Maybe a) -> Fold0 s a
- fromFold0 :: AFold0 a s a -> View s (Maybe a)
- type Fold s a = forall p. (Affine p, Traversing p, CoerceR p) => Optic' p 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
- afold :: Monoid r => ((a -> r) -> s -> r) -> AFold r s a
- type Fold1 s a = forall p. (Strong p, Traversing1 p, CoerceR p) => Optic' p 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
- afold1 :: Semigroup r => ((a -> r) -> s -> r) -> AFold1 r s a
- folded0 :: Fold0 (Maybe a) a
- filtered :: (a -> Bool) -> Fold0 a a
- 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
- (^?) :: s -> AFold0 a s a -> Maybe a
- preview :: MonadReader s m => AFold0 a s a -> m (Maybe a)
- preuse :: MonadState s m => AFold0 a s a -> m (Maybe a)
- is :: AFold0 a s a -> s -> Bool
- isnt :: AFold0 a s a -> s -> Bool
- lists :: AFold (Endo [a]) s a -> s -> [a]
- (^..) :: s -> AFold (Endo [a]) s a -> [a]
- nelists :: AFold1 (Nedl a) s a -> s -> NonEmpty a
- folds :: Monoid a => AFold a s a -> s -> a
- folds1 :: Semigroup a => AFold1 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
- foldsl :: AFold ((Endo - Dual) r) s a -> (r -> a -> r) -> r -> s -> r
- foldsr' :: AFold ((Endo - Dual) (Endo r)) s a -> (a -> r -> r) -> r -> s -> r
- foldsl' :: AFold ((Endo - Endo) r) s a -> (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
- foldslM :: Monad m => AFold (Endo (r -> m r)) s a -> (r -> a -> m r) -> r -> s -> m r
- traverses_ :: Applicative f => AFold (Endo (f ())) s a -> (a -> f r) -> s -> f ()
- concats :: AFold [r] s a -> (a -> [r]) -> s -> [r]
- aconcats :: Alternative f => AFold ((Endo - Endo) (f a)) s (f a) -> s -> f 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
- sums :: (Additive - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a
- multiplies :: (Multiplicative - Monoid) a => AFold ((Endo - Endo) a) s a -> s -> a
- 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
- has :: AFold (Additive Bool) s a -> s -> Bool
- hasnt :: AFold (Multiplicative Bool) s a -> s -> Bool
- contains :: Eq a => AFold (Additive Bool) s a -> a -> s -> Bool
- newtype Nedl a = Nedl {}

# Fold0

failing :: AFold0 a s a -> AFold0 a s a -> Fold0 s a infixl 3 Source #

If the first `Fold0`

has no focus then try the second one.

# Fold

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 #

# Fold1

folding1 :: Traversable1 f => (s -> a) -> Fold1 (f s) a Source #

Obtain a `Fold1`

from a `Traversable1`

functor.

`folding1`

f ≡`traversed1`

.`to`

f`folding1`

f ≡`fold1Vl`

`traverse1`

.`to`

f

# Optics

folded0 :: Fold0 (Maybe a) a Source #

The canonical `Fold0`

.

`>>>`

[1]`[Just 1, Nothing] ^.. folded . folded0`

filtered :: (a -> Bool) -> Fold0 a a Source #

Filter another optic.

`>>>`

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

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.

# Operators

(^?) :: s -> AFold0 a s a -> Maybe a infixl 8 Source #

An infix alias for `preview'`

.

(`^?`

) ≡`flip`

`preview'`

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.

`>>>`

Just 4`Left 4 ^? left'`

`>>>`

Nothing`Right 4 ^? left'`

is :: AFold0 a s a -> s -> Bool Source #

Check whether the optic is matched.

`>>>`

False`is just Nothing`

isnt :: AFold0 a s a -> s -> Bool Source #

Check whether the optic isn't matched.

`>>>`

True`isnt just Nothing`

(^..) :: s -> AFold (Endo [a]) s a -> [a] infixl 8 Source #

Infix alias of `lists`

.

`toList`

xs ≡ xs`^..`

`folding`

(`^..`

) ≡`flip`

`lists`

`>>>`

[[[1,2],[3]]]`[[1,2], [3 :: Int64]] ^.. id`

`>>>`

[[1,2],[3]]`[[1,2], [3 :: Int64]] ^.. traversed`

`>>>`

[1,2,3]`[[1,2], [3 :: Int64]] ^.. traversed . traversed`

`>>>`

[1,2]`(1,2) ^.. bitraversed`

(`^..`

) :: 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 ->`Traversal0'`

s a -> [a]

nelists :: AFold1 (Nedl a) s a -> s -> NonEmpty a Source #

Extract a `NonEmpty`

of the foci of an optic.

`>>>`

('h' :| "ello") :| ['w' :| "orld"]`nelists bitraversed1 ('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

foldsr :: AFold (Endo r) s a -> (a -> r -> r) -> r -> s -> r Source #

Right fold over an optic.

`>>>`

15`foldsr folded (+) 0 [1..5::Int64]`

foldsl :: AFold ((Endo - Dual) r) s a -> (r -> a -> r) -> r -> s -> r Source #

Left fold over an optic.

foldsr' :: AFold ((Endo - Dual) (Endo r)) s a -> (a -> r -> r) -> r -> s -> r Source #

Strict right fold over an 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 -> c`foldsl'`

::`Lens'`

s a -> (c -> a -> c) -> c -> s -> c`foldsl'`

::`View`

s a -> (c -> a -> c) -> c -> s -> c`foldsl'`

::`Fold`

s a -> (c -> a -> c) -> c -> s -> c`foldsl'`

::`Traversal'`

s a -> (c -> a -> c) -> c -> s -> c`foldsl'`

::`Traversal0'`

s a -> (c -> a -> c) -> c -> s -> c

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.

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.

traverses_ :: Applicative f => AFold (Endo (f ())) s a -> (a -> f r) -> s -> f () Source #

Applicative fold over an optic.

`>>>`

hello world`traverses_ both putStrLn ("hello","world")`

`traverse_`

≡`traverses_`

`folded`

mins :: Ord a => AFold ((Endo - Endo) a) s a -> a -> s -> a Source #

Compute the minimum of the targets of a totally ordered fold.

maxes :: Ord a => AFold ((Endo - Endo) a) s a -> a -> s -> a Source #

Compute the maximum of the targets of a totally ordered fold.

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.

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.

contains :: Eq a => AFold (Additive Bool) s a -> a -> s -> Bool Source #

Determine whether the targets of a `Fold`

contain a given element.