Skip to content
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

Map constructor error when the seq has duplicate keys #1094

Closed
FilippoPolo opened this issue Mar 25, 2020 · 1 comment
Closed

Map constructor error when the seq has duplicate keys #1094

FilippoPolo opened this issue Mar 25, 2020 · 1 comment
Assignees

Comments

@FilippoPolo
Copy link

Hi all,

There's a problem with the Map constructor that happens when the seq parameter contains multiple elements with the same key (but differing value). In .NET, this results in a Map containing the last seq value for a given key; in W#, this results in a Map containing the first seq value for a given key.

Repro:

let test() =
    let listWithDupes=[("A",1);("B",2);("A",3)]
    let m = Map listWithDupes
    let i = m.Item("A")
    // This is 3 on .NET, and 1 in W#.
    i

Tested on 4.6.1.381.

@Jand42 Jand42 self-assigned this Mar 26, 2020
@Jand42
Copy link
Member

Jand42 commented Mar 26, 2020

@FilippoPolo Thanks, good catch, indeed WS Proxy uses Seq.distinctby, which keeps first value https://github.com/dotnet-websharper/core/blob/master/src/stdlib/WebSharper.Collections/Map.fs#L36
I am adding a rev there, maybe optimizing a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants