Skip to content

Commit

Permalink
Add ifolded (purescript-contrib#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
twhitehead committed Aug 29, 2024
1 parent cc7a925 commit 75ec477
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Add `imapped` (#146 by @twhitehead)
- Add `ifolded` and `imapped` (#146 by @twhitehead)

Bugfixes:

Expand Down
9 changes: 7 additions & 2 deletions src/Data/Lens/Indexed.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import Control.Monad.State (evalState, get, modify)
import Data.Functor.Compose (Compose(..))
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Setter ((%~))
import Data.Lens.Types (Indexed(..), IndexedOptic, IndexedSetter, IndexedTraversal, Optic, Traversal, wander)
import Data.Newtype (unwrap)
import Data.Lens.Types (Indexed(..), IndexedOptic, IndexedFold, IndexedSetter, IndexedTraversal, Optic, Traversal, wander)
import Data.Newtype (wrap, unwrap)
import Data.Profunctor (class Profunctor, dimap, lcmap)
import Data.Profunctor.Star (Star(..))
import Data.Profunctor.Strong (first)
import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex)
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Tuple (curry, fst, snd)
Expand Down Expand Up @@ -47,6 +48,10 @@ iwander
-> IndexedTraversal i s t a b
iwander itr = wander (\f s -> itr (curry f) s) <<< unwrap

-- | Folds over a `FoldableWithIndex` container.
ifolded :: forall r i f t a b. Monoid r => FoldableWithIndex i f => IndexedFold r i (f a) t a b
ifolded = wrap <<< foldMapWithIndex <<< curry <<< unwrap <<< unwrap

-- | Sets over a `FunctorWithIndex` container.
imapped
:: forall i f a b
Expand Down

0 comments on commit 75ec477

Please sign in to comment.