Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ifolded and imapped (closes #147) #147

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
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
Loading