dimsuz
08/26/2022, 4:33 PMinterface HasAge { val age: Int }
@optics
data class Form(
override val age: Int
): HasAge {
companion object
}
// is exported out of the current "module"
val lens: Lens<HasAge, Int> = Form.age // compilation error
// in another module
fun transformAge(form: HasAge, lens: Lens<HasAge, Int>)
Can i somehow generate lens so that it can be assignable in the val lens
line?
Very likely that all this trouble points to the wrong design on my part, but the thing is that full type information is lost between the modules, I cannot export full data class Form
to be accessible to another module, all I've got is Any
which I can cast to HasAge
and then I thought I'd apply the lens (which also can be exported).Alejandro Serrano Mena
08/26/2022, 7:23 PMLens
directly
val lens: Lens<HasAge, Int> = Lens(
get = { it.age },
set = { a, i -> /* what should I do here */ }
}
Alejandro Serrano Mena
08/26/2022, 7:23 PMHasAge
methodsAlejandro Serrano Mena
08/26/2022, 7:25 PMForm.age
work? Well, if you write Lens<HasAge, Int>
that means you should be able to use any HasLens
, but your Form.age
only works for Form
!Alejandro Serrano Mena
08/26/2022, 7:26 PMinterface HasAge<A> {
val ageLens: Lens<A, Int>
}
@optics data class Form(val age: Int) {
companion object: HasAge<Form> {
override val ageLens = Form.age
}
}
dimsuz
08/26/2022, 9:43 PM