【发布时间】:2020-01-16 14:38:06
【问题描述】:
我有一个数据管道,其中每一步都需要更多数据字段。我想通过尊重不变性以一种功能性的方式做到这一点。我想知道是否有 F# 方法可以做到这一点?
// code that loads initial field information and returns record A
type recordA = {
A: int
}
// code that loads additional field information and returns record AB
type recordAB = {
A: int
B: int
}
// code that loads additional field information and returns record ABC
type recordABC = {
A: int
B: int
C: int
}
由于记录是密封的,我不能只是继承它们。如何避免必须使用与上一步完全相同的字段定义新记录并添加必填字段?最好我希望有一条记录,其中包含所有必填字段,并且在每个步骤中将这些字段分配给它们的值。
请注意,每一步添加的字段数可能超过 1 个。
【问题讨论】:
标签: f#