Skip to content

Commit

Permalink
Add imapped (purescript-contrib#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
twhitehead committed Aug 29, 2024
1 parent cbf678c commit cc7a925
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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)

Bugfixes:

Expand Down
10 changes: 9 additions & 1 deletion 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, IndexedTraversal, Optic, Traversal, wander)
import Data.Lens.Types (Indexed(..), IndexedOptic, IndexedSetter, IndexedTraversal, Optic, Traversal, wander)
import Data.Newtype (unwrap)
import Data.Profunctor (class Profunctor, dimap, lcmap)
import Data.Profunctor.Star (Star(..))
import Data.Profunctor.Strong (first)
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Tuple (curry, fst, snd)

Expand Down Expand Up @@ -46,6 +47,13 @@ iwander
-> IndexedTraversal i s t a b
iwander itr = wander (\f s -> itr (curry f) s) <<< unwrap

-- | Sets over a `FunctorWithIndex` container.
imapped
:: forall i f a b
. FunctorWithIndex i f
=> IndexedSetter i (f a) (f b) a b
imapped = mapWithIndex <<< curry <<< unwrap

-- | Traverses over a `TraversableWithIndex` container.
itraversed
:: forall i t a b
Expand Down

0 comments on commit cc7a925

Please sign in to comment.