Type synonym for an indexed fold.
Moduleoptics-core-0.4.1.1Haskell2010
Optics.IxFold
An IxFold is an indexed version of a Fold. See the "Indexed
optics" section of the overview documentation in the Optics module of the
main optics package for more details on indexed optics.
- 2 types
- 1 class
- 22 values
- Packageoptics-core-0.4.1.1
- Exports25
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceIxFold.hs
Formation
1 declarationIntroduction
1 declarationObtain an indexed fold by lifting itraverse_ like function.
ifoldVL . itraverseOf_ ≡ id
itraverseOf_ . ifoldVL ≡ id
Elimination
6 declarationsFold with index via embedding into a monoid.
Fold with index right-associatively.
Fold with index left-associatively, and strictly.
Fold with index to a list.
itoListOf (folded % ifolded) ["abc", "def"][(0,'a'),(1,'b'),(2,'c'),(0,'d'),(1,'e'),(2,'f')]
Note: currently indexed optics can be used as non-indexed.
toListOf (folded % ifolded) ["abc", "def"]"abcdef"
Traverse over all of the targets of an IxFold, computing an Applicative-based answer, but unlike itraverseOf do not construct a new structure.
itraverseOf_ each (curry print) ("hello","world")(0,"hello")(1,"world")
A version of itraverseOf_ with the arguments flipped.
Additional introduction forms
3 declarationsIndexed fold via FoldableWithIndex class.
Obtain an IxFold by lifting an operation that returns a FoldableWithIndex result.
This can be useful to lift operations from Data.List and elsewhere into an
IxFold.
itoListOf (ifolding words) "how are you"[(0,"how"),(1,"are"),(2,"you")]
Additional elimination forms
7 declarationsRetrieve the first entry of an IxFold along with its index.
iheadOf ifolded [1..10]Just (0,1)
Retrieve the last entry of an IxFold along with its index.
ilastOf ifolded [1..10]Just (9,10)
The ifindOf function takes an IxFold, a predicate that is also supplied the index, a structure and returns the left-most element of the structure along with its index matching the predicate, or Nothing if there is no such element.
When you don't need access to the index then findOf is more flexible in what it accepts.
The ifindMOf function takes an IxFold, a monadic predicate that is also supplied the index, a structure and returns in the monad the left-most element of the structure matching the predicate, or Nothing if there is no such element.
When you don't need access to the index then findMOf is more flexible in what it accepts.
Combinators
3 declarationsConvert an indexed fold to an IxAffineFold that visits the first element of the original fold.
For the traversal version see isingular.
Filter results of an IxFold that don't satisfy a predicate.
toListOf (ifolded %& ifiltered (>)) [3,2,1,0][1,0]
This allows you to traverse the elements of an IxFold in the opposite order.
Monoid structures
2 declarationsIxFold admits (at least) two monoid structures:
isumming concatenates results from both folds.
ifailing returns results from the second fold only if the first returns no results.
In both cases, the identity element of the monoid is ignored, which returns no results.
There is no Semigroup or Monoid instance for IxFold, because there is not a unique choice of monoid to use, and the (<>) operator could not be used to combine optics of different kinds.
Try the first IxFold. If it returns no entries, try the second one.
itoListOf (_1 % ifolded `ifailing` _2 % ifolded) (["a"], ["b","c"])[(0,"a")]itoListOf (_1 % ifolded `ifailing` _2 % ifolded) ([], ["b","c"])[(0,"b"),(1,"c")]
Subtyping
1 declarationTag for a fold.
Instances28Is, JoinKinds, IxOptic, ToReadOnly, ReadOnlyOptic, …
Is A_Getter A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_ReversedPrism A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Traversal A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_AffineFold A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_AffineTraversal A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_Iso A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_Getter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_ReversedPrism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold A_Traversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold An_AffineFold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold An_AffineTraversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Fold An_Iso kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Getter A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Lens A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Prism A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_ReversedPrism A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Traversal A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds An_AffineFold A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds An_AffineTraversal A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds An_Iso A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtyping(s ~ t, a ~ b) => IxOptic A_Fold s t a bDefined in optics-core-0.4.1.1 · Optics.Indexed.Core(s ~ t, a ~ b) => ToReadOnly A_Fold s t a bDefined in optics-core-0.4.1.1 · Optics.ReadOnlytype ReadOnlyOptic A_Fold = A_FoldDefined in optics-core-0.4.1.1 · Optics.ReadOnly
Re-exports
1 declarationA container that supports folding with an additional index.
Methods
Instances28FoldableWithIndex, …
FoldableWithIndex Int IntMapDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Int SeqDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Int NonEmptyDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Int ZipListDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Int []Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex () IdentityDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex () Par1Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex () MaybeDefined in indexed-traversable-0.1.4 · WithIndexIx i => FoldableWithIndex i (Array i)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void ProxyDefined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void U1Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void V1Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex k (Map k)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex k (Tuple2 k)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void (Const e)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void (Constant e)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex i f => FoldableWithIndex i (Rec1 f)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex i f => FoldableWithIndex i (Backwards f)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex i f => FoldableWithIndex i (Reverse f)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex i m => FoldableWithIndex i (IdentityT m)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex Void (K1 i c)Defined in indexed-traversable-0.1.4 · WithIndexFoldableWithIndex [Int] TreeDefined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product f g)Defined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Sum f g)Defined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :*: g)Defined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :+: g)Defined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (Compose f g)Defined in indexed-traversable-0.1.4 · WithIndex(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (f :.: g)Defined in indexed-traversable-0.1.4 · WithIndex