I want to pass a hashset to std/algorithm's nextPermutation and can't because nextPermutation accepts an OpenArray (an array or sequence), but not a hashset.
Are my options then:
New to programming so the answer (or other options) aren't clear to me.
Set is an unordered collection (of distinct entities) by definition, and permutation is a sequence of a set, so to get the next one you need some starting one. Moreover, nextPermutation accepts not just an openArray, but var openArray which means it works in-place.
Choosing between your two options requires more context. How do you use the data in a set? What operations are frequent? What properties of the structures you store the data in do you require?
My use case was Advent of Code 2015 where I have a list of cities to create a route through and I wanted my list of cities to be a hashset (to avoid duplicates) and then permutate all the possible options to calculate distance.
From your response, I understand by definition the hashset can't be ordered so isn't a good fit for that purpose, whereas the sequence.sorted.deduplicate worked perfect. I was just checking to see if hashset could have been used in retrospect. Thanks!
From your description it looks like the list of cities you need to work on is permanent and you process it only when you already have the full list of all cities at your disposal.
I think the most logical way is to first collect the list in a set, then convert a set to a sequence (using the items iterator or a sequtils.toSeq template), drop a set, work with permutations of a sequence.
In my experience, HashSet is usually the better choice then deduplicating a sequence, the latter being more relevant when you have some ordered data. However, when the amount of data is small and doesn't change often, deduplication as a step to prepare it for further processing is perfectly fine.