Skip to content

Add ValidationResult monad #24

@bartsokol

Description

@bartsokol

Validation is often handled by the Result type, but it has some drawbacks. First, the error type is fixed, and although it's quite flexible, it would be nice to have some type that reflects better the specific case of validation result. Second, it would be nice to have the actual object we're validating in the failed validation case as well, e.g. for better error handling.

Let's add ValidationResult type with two values, Passed and Failed. Passed case can hold the validated object, Failed case the object plus the validation error (I would try with a generic type, not sure if it would be possible to create flexible enough type to handle all possible validation errors).

The set of extensions for this type can be based upon, but will probably differ from, Result and Option types. It would be good to discuss here which methods would be useful for this type. For now, I would skip *Async variants and see how it goes (they may be added in next release if needed).

The structure for this type should be kept as it is for Result type in version 0.3 (soon to be released), so separate file for the type and then for extensions. Of course, all the extensions should be covered by the unit tests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions