Skip to content

Commit 1441836

Browse files
authored
Add ifolded and imapped (closes #147) (#147)
* Add `imapped` (#146) * Add `ifolded` (#146) * Update to latest package set * Tweak CI system as suggested by @garyb in #147 to get it building
1 parent cbf678c commit 1441836

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: |
4444
npm install bower [email protected]
4545
npx bower install
46-
npx pulp build -- --censor-lib --strict
46+
npx pulp build
4747
if [ -d "test" ]; then
4848
npx pulp test
4949
fi

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

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

1112
Bugfixes:
1213

packages.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
let upstream =
2-
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
2+
https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.15-20240829/src/packages.dhall
33

44
in upstream

src/Data/Lens/Indexed.purs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import Control.Monad.State (evalState, get, modify)
66
import Data.Functor.Compose (Compose(..))
77
import Data.Lens.Iso.Newtype (_Newtype)
88
import Data.Lens.Setter ((%~))
9-
import Data.Lens.Types (Indexed(..), IndexedOptic, IndexedTraversal, Optic, Traversal, wander)
10-
import Data.Newtype (unwrap)
9+
import Data.Lens.Types (Indexed(..), IndexedOptic, IndexedFold, IndexedSetter, IndexedTraversal, Optic, Traversal, wander)
10+
import Data.Newtype (wrap, unwrap)
1111
import Data.Profunctor (class Profunctor, dimap, lcmap)
1212
import Data.Profunctor.Star (Star(..))
1313
import Data.Profunctor.Strong (first)
14+
import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex)
15+
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
1416
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
1517
import Data.Tuple (curry, fst, snd)
1618

@@ -46,6 +48,21 @@ iwander
4648
-> IndexedTraversal i s t a b
4749
iwander itr = wander (\f s -> itr (curry f) s) <<< unwrap
4850

51+
-- | Folds over a `FoldableWithIndex` container.
52+
ifolded
53+
:: forall r i f t a b
54+
. Monoid r
55+
=> FoldableWithIndex i f
56+
=> IndexedFold r i (f a) t a b
57+
ifolded = wrap <<< foldMapWithIndex <<< curry <<< unwrap <<< unwrap
58+
59+
-- | Sets over a `FunctorWithIndex` container.
60+
imapped
61+
:: forall i f a b
62+
. FunctorWithIndex i f
63+
=> IndexedSetter i (f a) (f b) a b
64+
imapped = mapWithIndex <<< curry <<< unwrap
65+
4966
-- | Traverses over a `TraversableWithIndex` container.
5067
itraversed
5168
:: forall i t a b

0 commit comments

Comments
 (0)