question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation on List of Items

See original GitHub issue

I’ve been exploring the Validation class and have it working on validating a single item, but I want to validate each item in a list and return a single Validate item.

Example: I have a list of numbers, and I want to validate each of their lengths is less than 5.

From my understanding, the Error is actually a Seq which is appendable (a monoid?).

Can I get a Validate with any errors appended? I assume the type of Validation would also need to change from Validation<Error, string> to Validation<Error, List<string>> during this transition.

var list = new List<string>() { "1234", "12", "123456" };
var ValidateString = fun((string s) => s.Length < 5 ? Success<Error, string>(s) : Fail<Error, string>(Error.New("Too long")));

// would like a `Validation<Error, List<string>>` back, with both sides aggregated.
IEnumerable<Validation<Error, string>> validList = list.Map(t => ValidateString(t));

IEnumerable<Validation<Error, string>> validList = from i in list
                                                              select ValidateString(i);

 public class Error : NewType<Error, string>
    {
        public Error(string e) : base(e) { }
    }

The real use case is to take a list of emails, validate them, and return the list, if thats of any value.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gregbernscommented, Aug 29, 2017

Not sure why I didn’t think of that obvious option. Thanks Chris

0reactions
trbngrcommented, Aug 28, 2017

I would just use match.

validation.Match(
    Succ: identity,
    Fail: errors => errors.Map(x => x.Value)
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation of a list of objects in Spring
Spring boot docs about method level validation · org.springframework.validation.beanvalidation. · org.springframework.web.servlet.
Read more >
Validating Lists in a Spring Controller
In this tutorial, we'll go over ways to validate a List of objects as a parameter to a Spring controller. We'll add validation...
Read more >
Spring Request Body Validation For List
If there is some nested objects, then we have to add Valid annotation on a field with this objects, so that it will...
Read more >
Excel Drop Down Lists - Data Validation
Create a drop down list of items in a cell, with Excel's Data Validation feature. This will make data entry easier, and reduce...
Read more >
Validate list(object) variables - Terraform
I'm trying to set up a validation based on your suggestion and it doesn't seem to work for list(string) vars. I'm getting the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found