Validation on List of Items
See original GitHub issueI’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:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not sure why I didn’t think of that obvious option. Thanks Chris
I would just use match.