型システムで不変条件を強制する
from Integrity and Consistency in the Domain
不変条件 は型システムで直接表現することが可能
e.g. Order は 1 行以上の OrderLine を持つ
組み込みでは存在しない
自分で定義する
code:fsharp
type NonEmptyList<'a> = {
First: 'a
Last: 'a list
}
add や remove といった操作関数も必要になる
FSharpx.Collections のようなライブラリを使う
https://fsprojects.github.io/FSharpx.Collections/
NonEmptyList<'a> が用意されている radish-miyazaki.icon
https://fsprojects.github.io/FSharpx.Collections/reference/fsharpx-collections-nonemptylist-1.html
code:fsharp
type Order = {
...
OrderLine: NonEmptyList<OrderLine>
...
}