diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e721ba4..5d24f21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: run: | npm install bower pulp@16.0.0-0 npx bower install - npx pulp build -- --censor-lib --strict + npx pulp build if [ -d "test" ]; then npx pulp test fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb19aa..66af655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/packages.dhall b/packages.dhall index 582d6d3..188382b 100644 --- a/packages.dhall +++ b/packages.dhall @@ -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 diff --git a/src/Data/Lens/Indexed.purs b/src/Data/Lens/Indexed.purs index a041936..10d9a6f 100644 --- a/src/Data/Lens/Indexed.purs +++ b/src/Data/Lens/Indexed.purs @@ -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) @@ -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