Closed simonmcconnell closed 4 years ago
This does something similar.
let validateWithContext ctx =
Block.validate
>> Result.mapError (fun errors ->
ctx, errors)
let validateTextOptionWithContext<'block when 'block :> TextBlock> ctx =
Text.optional<'block>
>> Result.mapError (fun errors ->
ctx, errors)
let validatethese thing comment someNumber =
create
<!^> validateWithContext "Thing" thing
<*^> validateTextOptionWithContext "Comment" comment
<*^> validateTextOptionWithContext "SomeNumber" someNumber
Indeed @simonmcconnell, that's what I end up doing, but maybe this should be added to the API as I'm guessing everyone is going to be writing similar code
is there an idiomatic way to to get a list of errors from the validation with the context ala FsToolkit.ErrorHandling's
Result.tryCreate
as per the validation examples?will give you
Error: [[FirstCharacterInvalid '-']; [FirstCharacterInvalid '-']; [NotAnInt32]]
whereas if we use
Result.tryCreate
and the validation operators we get:The cleanliness of the result CE while accruing errors and their context is the dream.