org.finos.morphir.datamodel.Concept.Enum
See theEnum companion object
A discrimiated union type such as an ELM union (either with labels or not)
Given an Elm Datatype that looks like this:
type MyUnion =
= NoValue
| IntValue x:Int
| MultiValue x:Int y:String
| MultiValueAnon Int String // no labels for the types
Or a Scala 3 enum that looks like this:
enum MyUnion:
case NoValue
case IntValue(x:Int)
case MultiValue(x:Int, y:String)
// case MultiValueAnon(Int, String) // cannot have un-labeled unions in Scala3
The corresponding type-representation should look like this:
Enum(
Case("NoValue", List()),
Case("IntValue", List(Case.Field.Named("x", Schema.Int))),
Case("MultiValue", List(Case.Field.Named("x", Schema.Int), Case.Field.Named("y", Schema.String)))
Case("MultiValueAnon", List(Case.Field.Anon(Schema.Int), Case.Field.Anon(Schema.String)))
)
On the value level this should look as follows
// Given a type definition that looks like this (In Scala)
val x: MyUnion = MyUnion.IntValue(123)
// It's data-level encoding should look like this
Data.Case(
value: Data.Int(123)
case: Case("IntValue", List(Case.Field.Named("x", Schema.Int)))
schema: Schema.Enum
)
Attributes
- Companion
- object
- Graph
-
- Supertypes
Members list
In this article