-
Notifications
You must be signed in to change notification settings - Fork 182
Add unsafe functions for converting between Set and Map #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe we could instead have 'smaller' building blocks? toSet :: Map k a -> Set (Arg k a)
toMap :: Set (Arg k a) -> Map k a that can then be composed with other ones to generate all the variants? unsafeToSet :: (k -> a -> b) -> Map k a -> Set b
unsafeToSet f = Set.mapMonotonic (\(Arg k a) -> f k a) . toSet
unsafeToMap :: (b -> (k, a)) -> Set b -> Map k a
unsafeToMap f = toMap . Set.mapMonotonic (uncurry Arg . f) This isomorphism might also be useful elsewhere actually |
@alexfmpe Hah, see #817 and #814 (comment) |
Oh nevermind, you already stated all that in #814 (comment) . I thought containers avoided functions that were easily derivable from already exposed ones (unless a specialized version was more efficient) to keep the API small? |
Is there a use for these functions? I'm wary of adding new unsafe functions unless there is good reason for it. |
I'll defer that to @treeowl since these were his idea to add. |
@treeowl do you think these would be useful? |
In #814, @treeowl asked for functions like these:
And also ones that live in an
Applicative
, which I assume means ones like these:Note the lack of
Ord
constraints: these functions are unsafe in that it's the user's responsibility to make sure thek
andb
values agree on their ordering, just as it is formapMonotonic
. I think those are reasonable functions to add, but a little bit out of scope of that issue, hence this one.The text was updated successfully, but these errors were encountered: