Hi all, I'm trying to introduce Optics to an exist...
# arrow
i
Hi all, I'm trying to introduce Optics to an existing Android project [...]
I went through the usual setup: I added
kapt
, I added the dependencies:
Copy code
implementation(platform("io.arrow-kt:arrow-stack:1.0.1"))
    implementation("io.arrow-kt:arrow-core")
    implementation("io.arrow-kt:arrow-optics")
I added the classes:
Copy code
@optics
sealed class ContactInformation {
    companion object {}

    data class Email(val value: String) : ContactInformation()

    @optics
    sealed class Phone : ContactInformation() {
        companion object {}

        @optics
        data class MobilePhone(val number: String) : Phone() { companion object }

        @optics
        data class OfficePhone(val number: String) : Phone() { companion object }

        @optics
        data class HomePhone(val number: String) : Phone() { companion object }
    }

    data class HomeAddress(val street: String) : ContactInformation()
    object Pigeon : ContactInformation()
}

@optics
data class UserProfile(val name: String, val contact: ContactInformation) { companion object }
I should be able to do this now right?
Copy code
UserProfile.contact.phone.modify(joe) { MobilePhone("1234567890") }
I'm afraid the code generation does not happen 😞
am I missing something?
l
try adding
kapt "io.arrow-kt:arrow-meta:<version>"
, it worked for me
kapt "io.arrow-kt:arrow-meta"
will work with arrow-stack I guess
s
Yup, Optics still needs
kapt
and the arrow-meta dependency included https://arrow-kt.io/docs/optics/#basic-setup
i
ok, if I add this
Copy code
implementation("io.arrow-kt:arrow-optics:1.0.1")
    kapt("io.arrow-kt:arrow-meta:1.0.1")
it works 👍 this instead
Copy code
implementation(platform("io.arrow-kt:arrow-stack:1.0.1"))
implementation("io.arrow-kt:arrow-core")
implementation("io.arrow-kt:arrow-optics")
is not enough 👎
the documentation is a bit misleading tho
thanks @Luke @stojan
t
I got it working under maven 🙂 also don't forget to call
assemble
to actually generate the code