dave08
03/01/2023, 1:40 PMfoo.validate { }
using optics to return an Either<Nel<ValidationError>, Foo>
for validating data class hierarchies after they were deserialized...?ensure
and zipOrAccumulate
can't be used, because object instantiation isn't in the app code's control...Alejandro Serrano Mena
03/01/2023, 1:53 PMdave08
03/01/2023, 1:56 PMval foo = Foo(...)
val result: Either<ValidationError, Foo> = foo.validate {
Foo.baz eq 20
Foo.bar.bara.barb eq "something"
}
copy { }
... I just thought to use the same pattern for validation...!Alejandro Serrano Mena
03/01/2023, 2:13 PMvalidate
you don’t have a working value, you want to construct it when validation is successfuldave08
03/01/2023, 2:15 PMyou don’t have a working valueI'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.
copy { }
on an instance.this may work with a prismI really don't understand what a prism IS (or any other of these constructs except for setter and getter...)
val foo = Foo(...)
val result: Either<ValidationError, Foo> = foo.validate {
Foo.baz ensureThat { it == 20 }
Foo.bar.bara.barb ensureThat { it.startsWith("something") }
}