Validation<'a, 'b> list -> Validation<'a list, 'b list>
See original GitHub issueI have a scenario the user creates n objects. If all objects are valid I want to get all the objects, if any one of them is invalid, I want to get all the errors, something like:
Validation<'a, 'b> list -> Validation<'a list, 'b list>
.
I’m posting this here as it might be a common scenario.
Based on @gusty’s comment on a previous issue, I ended up with:
let f (vs : Validation<_, _> list): Validation<_ list, _> = traverse (first result) vs
(it needed a little more help with the types.)
Which gives me the behaviour I would expect:
let private f (vs : Validation<_, _> list): Validation<_ list, _> = traverse (first result) vs
[<Fact>]
let ``My test`` () =
let x1 : Validation<string, _> list = [ Success 1; Success 2; Success 3 ]
let e1 : Validation<string list, _> = Success [ 1; 2; 3 ]
let x2 = [ Success 1; Failure "a"; Success 3 ]
let e2 : Validation<_, int list> = Failure [ "a" ]
let x3 : Validation<_, int> list = [ Failure "a"; Failure "b"; Failure "c" ]
let e3 : Validation<_, int list> = Failure [ "a"; "b"; "c" ]
test <@ f x1 = e1 @>
test <@ f x2 = e2 @>
test <@ f x3 = e3 @>
Thank you for you help @gusty, @DunetsNM. One slight follow-up, is there an appropriate name for this function?
Originally posted here: https://github.com/fsprojects/FSharpPlus/issues/51#issuecomment-586202997
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Excel Drop Down Lists - Data Validation
Easy steps to make drop down list wth Excel data validation. Show list of valid entries, reduce data entry errors. Videos, written notes ......
Read more >Apply data validation to cells
Select one or more cells to validate. · On the Data tab, in the Data Tools group, click Data Validation . · On...
Read more >Data validation with conditional list - Excel formula
Data validation rules are triggered when a user adds or changes a cell value. This formula takes advantage of this behavior to provide...
Read more >Excel formula: Data validation exists in list - Excelchat
Want to learn how to check if Data validation exists in list? ... Here we have a table named “Item List” in column...
Read more >Custom Data Validation in Excel : formulas and rules
Learn how to use custom Data Validation in Excel with your own rules and formulas. Formula examples to allow only numbers or text...
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
One more tip:
If you don’t write a generic
result
F# is able to infer the whole function.traverse (first List.singleton) vs
so you don’t need to pre-create the function.We might add Bitraversable and Biapplicative to the library.
Bitraversable is almost there as many extensions have
bisquence
andbitraverse
already.Perfect, thank you @gusty!