Skip to content

Add power to validate and ensure #32

Open
@FintanH

Description

@FintanH

It would be really useful if the validate and ensure used (a -> Maybe b) instead of (a -> Bool). This would allow the user to output an updated, validated value as a result.

For example, my current use case is that I'm validating an Integer to a Natural, ensuring that the Integer is (n >= 0).

So I could do:

positive :: Integer -> Validation Errors Natural
positive n = 
  validate (pure $ NegativeVal n) (if n <= then Just $ fromInteger n else Nothing) n

What do you think? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions