do we have a way of making a data class that utili...
# arrow
r
do we have a way of making a data class that utilize
Either
for the validation and has a sensible
copy
without one having to do too many manual overrides. I.e., one could do for construction:
Copy code
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
y
Newest Kotlin update has
@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 convenience
r
hmm, at least better 🙂 where can I read about
Raise
receivers?
y
r
thanks
r
@Riccardo Cardin thanks to you too 🙂
👍 1