purescript-contrib / purescript-profunctor-lenses

Pure profunctor lenses
MIT License
144 stars 51 forks source link

Add `ifolded` and `imapped` #146

Open twhitehead opened 3 weeks ago

twhitehead commented 3 weeks ago

The library has itraversed to give an IndexedTraversal for any TraversableWithIndex.

It would be also nice to have ifolded and imapped to give an IndexedSetter for any FunctorWithIndex and an IndexedFold for any FoldableWithIndex.

This would introduce no additional dependencies as both FoldableWithIndex and FunctorWithIndex are defined in the foldable-traversable package that is already depended on for TraversableWithIndex.

I'll submit a pull request shortly.

jamesdbrock commented 3 weeks ago

For reference

https://hackage.haskell.org/package/lens-5.3.2/docs/Control-Lens-Indexed.html#v:ifolded

https://hackage.haskell.org/package/lens-5.3.2/docs/Control-Lens-Indexed.html#v:imapped

twhitehead commented 3 weeks ago

Just stumbled across the fact that, while both folded and traversed are present, mapped is missing.

Not a big deal as, for profunctor lenses, it is just technically

mapped :: forall f a b. Functor f => Setter a b (f a) (f b)
mapped = map

Still maybe a good idea to throw it in for completeness?

Saves a few brain cycles when you reach for it and realize it isn't there. :grinning: