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...?dave08
03/01/2023, 1:42 PMensure
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"
}
dave08
03/01/2023, 1:57 PMdave08
03/01/2023, 1:57 PMdave08
03/01/2023, 2:08 PMcopy { }
... 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 successfulAlejandro Serrano Mena
03/01/2023, 2:14 PMdave08
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.
dave08
03/01/2023, 2:16 PMcopy { }
on an instance.dave08
03/01/2023, 2:17 PMthis may work with a prismI really don't understand what a prism IS (or any other of these constructs except for setter and getter...)
dave08
03/01/2023, 2:18 PMdave08
03/02/2023, 11:30 AMval foo = Foo(...)
val result: Either<ValidationError, Foo> = foo.validate {
Foo.baz ensureThat { it == 20 }
Foo.bar.bara.barb ensureThat { it.startsWith("something") }
}