Closed prSquirrel closed 1 year ago
.map
/ .flatMap
for now, .filter
would be trivial to add. Would appreciate your feedback @noam-almog @holograph 🙂
Right out the gate, thank you! At a glance this looks very good, but I'll need to dig a little deeper (plus, only @noam-almog has commit/admin privileges now...).
@prSquirrel the build is currently failing, can you take a look ?
@noam-almog fixed!
For some reason 2.11 doesn't infer method to function -> function to validator implicit so I made it an explicit function.
I suppose there was some improvement in 2.12+
Any updates on this? 🙂
By and large, looks very good. One concern I have is around indices on flatmapped arrays; once you change the validated array, indices become rather meaningless (e.g. in the Seq(0, 2) test the result shows the problem at index 1 of the resulting sequence), and error messages become somewhat problematic as well.
It might be a better idea to 1. Report indices on the source sequence or not at all; 2. Maybe force overriding the error message on map/flatMap (for example, if I map via toString and check for nonnegative numbers via startsWith, the error makes no sense).
I’m not clear on how flatMap makes sense from a usage standpoint, but other than the above comments I don’t see any reason not to.
Makes the following syntax instances valid:
I'm not entirely sure supporting
flatMap
or any other non-structure-preserving operation is the right way to go. Suppose you haveval coll = Seq(0, 2)
and a functionval extend = (i: Int) => Seq(i, i + 1)
.coll flatMap extend
would produceSeq(0, 1, 2, 3)
. Now, if element1: Int
is invalid,coll.each flatMap extend is valid
would refer to [at index 1] - after collection transformation. This works, but may overcomplicate validators.Also, replaced Traversable[_] with Iterable[_] because of 2.13 collections rework.