zsmb
02/24/2019, 5:59 PMinterface Eq<F> {
fun F.eqv(b: F): Boolean
fun F.neqv(b: F): Boolean = !eqv(b)
}
data class User(val id: Int) {
companion object
}
@extension interface UserEq : Eq<User> {
override fun User.eqv(b: User): Boolean = id == b.id
}
Now, I can make the neqv
call work, as that extension is generated:
val user1 = User(1)
val user2 = User(2)
user1.neqv(user2)
However, I don't get an eqv
extension generated. I did get an eq
extension that I could then open a scope on with run
, but this isn't very neat:
User.eq().run {
user1.eqv(user2)
}
So... Is there something I could fix in my code to make Arrow generate the eqv
extension that I could use like this?
user1.eqv(user2) // right now, unresolved reference: eqv
kioba
02/24/2019, 7:08 PMeqv
as extension on the User type. Just he Companion obbject going to be generated
fun User.neqv(b: User): Boolean = aaa.aaa.kioba.bbb.bbb.User.eq().run {
this@neqv.neqv(b) as kotlin.Boolean
}
fun Companion.eq(): UserEq = object : aaa.aaa.kioba.bbb.bbb.UserEq { }
kioba
02/24/2019, 7:23 PM0.8.2
I could end up generating the function with a workaround. Seems like the annotation will only generate the extension if the base interface has a default implementation. If you modify your EQ<F> interface according to this:
interface Eq<F> {
fun F.eqvImp(b: F): Boolean
fun F.eqv(b: F): Boolean = eqvImp(b)
fun F.neqv(b: F): Boolean = !eqvImp(b)
}
it will generate the User.eqv
function for you.
Edit: still trying to figure out the annotation processor why filtering out the functions with non default impl.zsmb
02/24/2019, 7:48 PMraulraja
02/25/2019, 9:38 AM@JvmName("eqv")
@Suppress(
"UNCHECKED_CAST",
"USELESS_CAST",
"EXTENSION_SHADOWED_BY_MEMBER",
"UNUSED_PARAMETER"
)
fun <A> Kind<ForListK, A>.eqv(EQ: Eq<A>, arg1: Kind<ForListK, A>): Boolean = arrow.data.ListK.eq<A>(EQ).run {
this@eqv.eqv(arg1) as kotlin.Boolean
}
raulraja
02/25/2019, 9:39 AM