Skip to content

Commit

Permalink
Docs for sealed hierarchy lenses (#273)
Browse files Browse the repository at this point in the history
Documentation related to arrow-kt/arrow#3359
  • Loading branch information
serras authored Feb 28, 2024
1 parent ab7bab5 commit 3ac4b62
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions content/docs/learn/immutable-data/lens.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,31 @@ fun Person.moveToAmsterdamInside(): Person = copy {
}
```
<!--- KNIT example-lens-domain-03.kt -->

### Sealed class hierarchies

If you have a set of classes with a common sealed parent, then lenses
can be generated for those properties shared by all of them.
Those properties must appear already in the common parent.

For example, the plug-in generates a lens of the `name` field given
the code below. This lens complements the [prisms](../prism-iso)
that are generated to focus on each of the two subclasses.

```kotlin
@optics sealed interface User {
val name: String

companion object

data class Person(
override val name: String,
val age: Int
): User

data class Company(
override val name: String,
val vat: VATNumber
): User
}
```

0 comments on commit 3ac4b62

Please sign in to comment.