Sets
Currently in a Concerto model, it is not possible to define a field as being a set - a collection of unique values.
Feature Request 🛍️
Allow a model author to define a field as being a set, and at validation time enforce uniqueness on the values in stored in that set.
Use Case
Imagine a model that backs a multiple choice question in a survey, such as "Which of these fruits do you like?".
The fruits could be modelled as an enumeration:
enum Fruit {
o APPLE
o PEAR
o BANANA
o MANGO
}
Today, all you can do is model the list of fruits you like as a list:
concept Survey {
o Fruit[] fruits
}
But there is nothing in the model to say that you only want to allow unique fruit values in the list, so you could have:
{
"$class": "Survey",
"fruits": [
"APPLE",
"APPLE",
"APPLE",
"APPLE"
]
}
Possible Solution
A few syntax options spring to mind:
- Some kind of generics-like way of expressing a
Settype:
concept Survey {
o Set<Fruit> fruits
}
- A uniqueness constraint on a list
concept Survey {
o Fruit[] fruits unique
}
I would suggest that whatever we do, we restrict the type of values in a set to primitive types and enumerations.
Context
Detailed Description
I like it, this feature would pair nicely with #447
There is a language design for this feature at https://github.com/accordproject/concerto/wiki/Aggregate-Types-Design-(Working-Draft)