-
Notifications
You must be signed in to change notification settings - Fork 31
Couple new foldable functions to Data.Map
#42
Conversation
Btw Also if you're happy with these, to be consistent we should add |
What if we just generalize the types of |
I did consider generalizing For toList :: forall f k v. (Unfoldable f) => Map k v -> f (Tuple k v)` |
👍 |
Sorry, this has been in my inbox for two weeks and I keep meaning to get round to reviewing it. Thanks for the PR. It looks good to me, and |
Ah no I didn't try We all seem to be referring to the functions I added by different names. What naming convention should we go by? My thoughts on each that I've seen:
I'd say |
I prefer |
I was just looking for this too (@soro asked me about it) -- fromFoldable seems the appropriate name. |
👍 👍 👍 for |
* `Data.Map.fromFoldable` * `Data.Map.fromFoldableWith` * `Data.StrMap.fromFoldable` * `Data.StrMap.fromFoldableWith` Other things: * Added basic tests * Corrected doc comments on some functions mentioning array when they meant list * Modified Gen import in tests as there was a compiler warning about it * Docs regenerated
I'm currently investigating the As for the |
Looks good to me! Thanks, and sorry for the delay. Nothing is a breaking change here, right? |
Couple new foldable functions to `Data.Map`
👍 |
Tagged as 0.5.4 |
Thanks! |
Hooray :) Incidentally, I like the idea of |
@hdgarrood just been playing around with a class for this: https://github.com/LiamGoodacre/purescript-twofoldable/blob/master/docs/Data/Twofoldable.md |
@LiamGoodacre Have you seen |
This guy? type IndexedTraversal i s t a b =
forall p f. (Indexable i p, Applicative f) => p a (f b) -> s -> f t http://haddock.stackage.org/lts-3.18/lens-4.12.3/Control-Lens-Type.html#t:IndexedTraversal |
Yes. I don't fully understand it yet, but it seems relevant to these sorts of functions where you're folding/traversing with a key or index. |
Just found this too: ifoldMapOf :: IndexedGetting i m s a -> (i -> a -> m) -> s -> m
ifoldMapOf :: Monoid m => IndexedFold i s a -> (i -> a -> m) -> s -> m
-- version where I've specialised to Map:
ifoldMapOf :: Monoid m => IndexedFold k (Map k v) v -> (k -> v -> m) -> Map k v -> m And then this: class Foldable f => FoldableWithIndex i f | f -> i where
ifoldMap :: Monoid m => (i -> a -> m) -> f a -> m
-- ... |
Perhaps the most general thing which can be exported is an indexed traversal, then? (No |
Added:
foldableToMap
foldableToMapWith
Other things:
These okay?