Was also wondering if there could be a `foo.valida...
# arrow
d
Was also wondering if there could be a
foo.validate { }
using optics to return an
Either<Nel<ValidationError>, Foo>
for validating data class hierarchies after they were deserialized...?
It could be used when
ensure
and
zipOrAccumulate
can't be used, because object instantiation isn't in the app code's control...
a
how would you envision it working?
d
Copy code
val foo = Foo(...)

val result: Either<ValidationError, Foo> = foo.validate {
   Foo.baz eq 20
   Foo.bar.bara.barb eq "something"
 }
Each line that doesn't pass could be accumulated in the Left.
And if they all pass, Right is returned with Foo
Does this make any sense @Alejandro Serrano Mena? It's you that had the great idea to add
copy { }
... I just thought to use the same pattern for validation...!
a
the problem here is that usually to call
validate
you don’t have a working value, you want to construct it when validation is successful
this may work with a prism, but would need a bit more work
d
you don’t have a working value
I'm not sure I understand...? I fixed up my example above, we already HAVE an instance of foo... we're just returning it if it validates.
Just like you run
copy { }
on an instance.
this may work with a prism
I really don't understand what a prism IS (or any other of these constructs except for setter and getter...)
And there's no tutorials out there that explain it apart from those docs being worked on...
I was looking at the Copy implementation, and was thinking maybe something like this might be easier/more flexible? Is this possible @Alejandro Serrano Mena?
Copy code
val foo = Foo(...)

val result: Either<ValidationError, Foo> = foo.validate {
   Foo.baz ensureThat { it == 20 }
   Foo.bar.bara.barb ensureThat { it.startsWith("something") }
 }