accordproject / concerto

Business schema language and runtime
https://concerto.accordproject.org
Apache License 2.0
119 stars 106 forks source link

Sets #543

Open sstone1 opened 1 year ago

sstone1 commented 1 year ago

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:

1) Some kind of generics-like way of expressing a Set type:

concept Survey {
  o Set<Fruit> fruits
}

2) 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

mttrbrts commented 1 year ago

I like it, this feature would pair nicely with #447

mttrbrts commented 7 months ago

There is a language design for this feature at https://github.com/accordproject/concerto/wiki/Aggregate-Types-Design-(Working-Draft)