fsharp-hashcollections icon indicating copy to clipboard operation
fsharp-hashcollections copied to clipboard

How to create a `HashSet` from `seq` with a custom comparer?

Open xperiandri opened this issue 1 year ago • 1 comments

xperiandri avatar May 20 '24 14:05 xperiandri

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

mvkara avatar Jun 07 '24 07:06 mvkara