Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

["Request"] Generate Lens for sealed class abstract val #2829

Closed
Kernald opened this issue Sep 27, 2022 · 1 comment
Closed

["Request"] Generate Lens for sealed class abstract val #2829

Kernald opened this issue Sep 27, 2022 · 1 comment

Comments

@Kernald
Copy link

Kernald commented Sep 27, 2022

What version are you currently using?
1.1.3

What would you like to see?
As per arrow-kt/arrow-optics#5 which seems to have been lost when things were consolidated in this repo, with a sealed class of the following shape:

sealed class Example {
  abstract val name: String

  data class One(override val name: String, val int: Int) : Example()
  data class Two(override val name: String, val long: Long) : Example()
  data class Three(override val name: String, val double: Double) : Example()
}

I would love seeing a generated val name: Lens<Example, String>, which would look like this:

val name: Lens<Example, String> = Lens(
  get = { it.name },
  set = { example, name ->
    when (example) {
      is One -> example.copy(name = name)
      is Two -> example.copy(name = name)
      is Three -> example.copy(name = name)
    }
  },
)

This is a bit boilerplate-y, and needs updating whenever a sub-type is added. It seems like a good candidate for code generation.

@serras
Copy link
Member

serras commented Feb 8, 2024

Fixed by #3359, will be released on 1.2.2.

@serras serras closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants