Open
Description
I was thinking today that it might be nice to have things like
fromSetA :: Applicative f => (k -> f a) -> Set k -> f (Map k a)
fromSetWithIndexA :: Applicative f => (Int -> k -> f a) -> Set k -> f (Map k a)
fromSetWithIndex :: (Int -> k -> a) -> Set k -> Map k a
fromSetWithIndex f s = runIdentity (fromSetWithIndexA (coerce f) s)
These would let the user produce the values in an arbitrary Applicative
, and the WithIndex
version would let the passed function know where in the set it was working. For example,
counting :: Set k -> Set k Int
counting = fromSetWithIndex (\i _ -> i)
-- counting (fromList "abc") = fromList [('a', 0), ('b', 1), ('c', 2)]
I'd also really love to get something like mergeA
for Set
, and ideally something similar that would combine sets with maps. Having to convert a set to a map first seems pretty bad.