Set data type
toastal opened this issue · comments
Is your feature request related to a problem? Please describe.
For collection types, Nickel supports: records, dictionary, arrays, but one common structure missing is Set
, an unordered collection like an array where all values must be unique. Uniqueness can prevent certain kinds of errors where the consumer should need to consider duplicate values, but also comes with a grab bag of handy combinators like union
, intersect
, difference
, merge
, etc.
Describe the solution you'd like
Add a new data type: Set T
+ stdlib
module std-set
Describe alternatives you've considered
Making a bunch of contracts around Array T
.
Additional context
This is a common data structure in most languages. It’s been a long personal pain point with its absence in JSON, however alternatives like EDN do support it. Being able to assert a JSON Array as a Set would be very useful.
I wonder, do you want a builtin type Set
that would be natively handled by Nickel, or some kind of standard library module that implements Set
using more basic constructions? Or, maybe, you don't care and just want Set
🙂
Sets are also basic blocks for building more advanced compound types too
Weighing in here as someone who also encountered use cases for Set
, I believe a native implementation would be nicer, though the only reason I could think of is performance.😂