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

Language | Haskell2010 |

An `AffineFold`

is a `Fold`

that contains at most one
element, or a `Getter`

where the function may be
partial.

## Synopsis

- type AffineFold s a = Optic' An_AffineFold NoIx s a
- afolding :: (s -> Maybe a) -> AffineFold s a
- preview :: Is k An_AffineFold => Optic' k is s a -> s -> Maybe a
- previews :: Is k An_AffineFold => Optic' k is s a -> (a -> r) -> s -> Maybe r
- filtered :: (a -> Bool) -> AffineFold a a
- isn't :: Is k An_AffineFold => Optic' k is s a -> s -> Bool
- afailing :: (Is k An_AffineFold, Is l An_AffineFold) => Optic' k is s a -> Optic' l js s a -> AffineFold s a
- data An_AffineFold

# Formation

type AffineFold s a = Optic' An_AffineFold NoIx s a Source #

Type synonym for an affine fold.

# Introduction

afolding :: (s -> Maybe a) -> AffineFold s a Source #

Create an `AffineFold`

from a partial function.

`>>>`

Just 'f'`preview (afolding listToMaybe) "foo"`

# Elimination

preview :: Is k An_AffineFold => Optic' k is s a -> s -> Maybe a Source #

Retrieve the value targeted by an `AffineFold`

.

`>>>`

`let _Right = prism Right $ either (Left . Left) Right`

`>>>`

Just 'x'`preview _Right (Right 'x')`

`>>>`

Nothing`preview _Right (Left 'y')`

previews :: Is k An_AffineFold => Optic' k is s a -> (a -> r) -> s -> Maybe r Source #

Retrieve a function of the value targeted by an `AffineFold`

.

# Computation

# Additional introduction forms

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

Filter result(s) of a fold that don't satisfy a predicate.

# Additional elimination forms

isn't :: Is k An_AffineFold => Optic' k is s a -> s -> Bool Source #

Check to see if this `AffineFold`

doesn't match.

`>>>`

True`isn't _Just Nothing`

# Semigroup structure

afailing :: (Is k An_AffineFold, Is l An_AffineFold) => Optic' k is s a -> Optic' l js s a -> AffineFold s a infixl 3 Source #

Try the first `AffineFold`

. If it returns no entry, try the second one.

`>>>`

Just (Left 1)`preview (ix 1 % re _Left `afailing` ix 2 % re _Right) [0,1,2,3]`

`>>>`

Just (Right 2)`preview (ix 42 % re _Left `afailing` ix 2 % re _Right) [0,1,2,3]`

*Note:* There is no `summing`

equivalent, because `asumming = afailing`

.

# Subtyping

data An_AffineFold Source #

Tag for an affine fold.