concerto icon indicating copy to clipboard operation
concerto copied to clipboard

Sets

Open sstone1 opened this issue 3 years ago • 2 comments

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
}
  1. 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

sstone1 avatar Nov 07 '22 19:11 sstone1

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

mttrbrts avatar Nov 07 '22 20:11 mttrbrts

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

mttrbrts avatar Feb 27 '24 14:02 mttrbrts