innoave/valid

Flat argument list instead of nested tuples for closures in `Validation` methods

Opened this issue · 2 comments

Currently the closures in the methods Validation::and_then and Validation::map` get passed nested tuples which can become really ugly with more and more arguments.

We should find a way to flatten the values collected so far by the Validation type, so that the closures either get a list of arguments passed or one flat tuple with all the values.

This will be a breaking change in the API, but I think the advantage outweighs any pain with changing existing implementations.

Hello from the future..!)

Several times ago i encruntered with the same problem/question, when was trying implement some similar.

Perhaps you have found a solution? There is hardly a universal solution since each possible tuple structure/size requires a separate implementation.

I've got this idea from looking at crates like warp and axum. When I last looked at these, they used a macro to implement some kind of "flatting" trait for tuples of two, three, four and so on up to a number of elements (e.g. 32 elements) in a tuple. So yes it requires a separate implementation for each supported typle size. The solution assumes that for most applications there is no need for more than a certain number of arguments in a tuple.