|
|
|
|
|
by nybble41
1464 days ago
|
|
When the final record should have either Yes or No, but the there is an intermediate state where the answer could be missing, you want something like a Maybe<Bool> which you can map to a simple Bool as part of validation. Ideally you'd use a functor-style parameter for this, for example in Haskell: data Record f = Record { …, someField ∷ f Bool, … }
type PartialRecord = Record Maybe
type CompleteRecord = Record Identity
getCompletedRecord ∷ PartialRecord → Maybe CompleteRecord
getCompletedRecord (Record { …, someField, … }) =
Record <$> … <*> (Identity <$> someField) <*> …
This way you can define your record type once and handle all the missing fields in a uniform way, and functions can easily indicate whether they expect a partial record full of Maybes or a complete record with no potentially missing fields. You can use the same type definition for other things, too, by substituting different functors in place of Maybe or Identity. For example, `Record ToString` where `ToString a` is a newtype over `(a → String)` could be a record of functions describing how to render each field as a string.In the DB you would need to store incomplete records in a separate table, since they have different validation rules. Queries against the main table should be able to assume that all the records are complete. |
|