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

How to create a HashSet from seq with a custom comparer? #32

Open
xperiandri opened this issue May 20, 2024 · 1 comment
Open

How to create a HashSet from seq with a custom comparer? #32

xperiandri opened this issue May 20, 2024 · 1 comment

Comments

@xperiandri
Copy link

No description provided.

@xperiandri xperiandri changed the title How to create HashSet from seq with custom comparer? How to create a HashSet from seq with a custom comparer? May 20, 2024
@mvkara
Copy link
Collaborator

mvkara commented Jun 7, 2024

Another function in the HashSet/Map to do so could work for your case? Something like:

let ofSeqWithComparer (s: #seq<KeyValuePair<'k, 'v>>) : HashMap<'k, 'v, 'tk> =
        let eqComparer = new 'tk()
        HashMap<_, _, _>(
            HashTrie.ofSeq keyExtractor eqComparer s empty.HashTrieRoot,
            eqComparer)

Then at usage site you could do:

let c : HashMap<_, _, 'comparerType> = data |> HashMap.ofSeqWithComparer

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

No branches or pull requests

2 participants