Rohde Fischer
09/14/2024, 6:06 PMEither
for the validation and has a sensible copy
without one having to do too many manual overrides. I.e., one could do for construction:
data class Foo private constructor(val x: Int) {
companion object {
fun create(x: Int): Either<Error, Foo> { /* domain logic for new foo */ }
}
}
or its sibling with operator fun invoke
but what about copy? That will still expose my private and unsafe constructor. I could of course do the validation in an init
as well and "bite the bullet" having an exception throwing copy 😕 but I'd much rather have a copy
using the create
function or invoke
Youssef Shoaib [MOD]
09/14/2024, 6:09 PM@ConsistentCopyVisibility
or something like that. That'll at least hide the default copy, then you can define your own. Also, I'd suggest having your methods taking a Raise
receiver instead for convenienceRohde Fischer
09/14/2024, 6:16 PMRaise
receivers?Youssef Shoaib [MOD]
09/14/2024, 6:20 PMRohde Fischer
09/14/2024, 6:22 PMRiccardo Cardin
09/15/2024, 7:25 AMRohde Fischer
09/19/2024, 6:09 PM