Skip to content

Commit

Permalink
Add ifolded and imapped (closes #147) (#147)
Browse files Browse the repository at this point in the history
* Add `imapped` (#146)

* Add `ifolded` (#146)

* Update to latest package set

* Tweak CI system as suggested by @garyb in #147 to get it building
  • Loading branch information
twhitehead authored Sep 18, 2024
1 parent cbf678c commit 1441836
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
npm install bower [email protected]
npx bower install
npx pulp build -- --censor-lib --strict
npx pulp build
if [ -d "test" ]; then
npx pulp test
fi
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 `ifolded` and `imapped` (#146 by @twhitehead)

Bugfixes:

Expand Down
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let upstream =
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.15-20240829/src/packages.dhall

in upstream
21 changes: 19 additions & 2 deletions src/Data/Lens/Indexed.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ 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.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 @@ -46,6 +48,21 @@ 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
. 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 1441836

Please sign in to comment.