Open masaeedu opened 5 years ago
That looks neat, @masaeedu! What are the types of the two functions?
@davidchambers Weird, looks like I edited away the types I just edited in. Here they are:
type FoldableWithKey k f = {
foldMapWithKey : Monoid m -> (k -> v -> m) -> f v -> m
}
and:
type TraversableWithKey k f = {
traverseWithKey : Applicative f -> (k -> a -> f b) -> t a -> f (t b)
}
I'm actually still a little bit torn about whether it's a better idea to have foldMapWithKey
and traverseWithKey
or just: type WithKey k f = { withKey : f a -> f (k, a) }
. If you do it the second way you can implement traverseWithKey
just once for anything that happens to be both Traversable
and WithKey
(although of course you have to implement withKey
for everything).
It'd be handy to have something like
foldMapWithKey
so you can do:Similarly
traverseWithKey
.