Add Map.merge to FSharp.Core#19994
Open
bbatsov wants to merge 1 commit into
Open
Conversation
cf97200 to
f0b5cdd
Compare
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
Combines two maps into one, using a caller-supplied function to resolve the values of keys present in both maps. The right-biased "last one wins" merge from the original proposal is just a special case of the combiner form (Map.merge (fun _ _ v2 -> v2)). Implements fsharp/fslang-suggestions#560.
f0b5cdd to
84c93dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now that #19265 (print/printn) is in good shape, I went looking for other small, self-contained additions to FSharp.Core I could help with, and landed on suggestion #560: a
Map.mergefunction. It's approved-in-principle and gets asked for fairly regularly, so it felt worth a shot.Map.mergecombines two maps into one. When a key is present in both, a caller-supplied function resolves the two values:I went with the combiner form rather than the plain "last one wins" from the original 2017 proposal, since right-biased merge is just a trivial special case of it (
Map.merge (fun _ _ v2 -> v2)).One caveat: unlike the print/printn ticket, this suggestion never got a detailed RFC, so the exact shape (name, argument order, combiner vs. right-biased) is really my best guess and probably wants a maintainer's eye before it goes any further.
Suggestion: fsharp/fslang-suggestions#560