Created
February 7, 2018 16:27
-
-
Save nomisRev/5a1f44647b3ce2e1ae96c133631e8ed5 to your computer and use it in GitHub Desktop.
Optics DSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lenses data class Street(val number: Int, val name: String) | |
@lenses data class Address(val city: String, val street: Street) | |
@lenses data class Company(val name: String, val address: Address) | |
@lenses data class Employee(val name: String, val company: Company?) | |
@lenses data class Employees(val employees: ListKW<Employee>) | |
employees.setter().employees.each().company.nullable.address.street.name | |
.modify(String::toUpperCase) //modifies all employees companies address street name. | |
employees.setter().employees.get(0).company.nullable.address.street.name | |
.modify(String::toUpperCase) //modifies first employee his companies address street name. | |
@lenses data class Db(val content: MapKW<Keys, String>) | |
val db = Db(mapOf( | |
One to "one", | |
Two to "two", | |
Three to "three", | |
Four to "four" | |
).k()) | |
db.setter().content.get<Db, MapKW<Keys, String>, Keys, String>(Three) | |
.modify(String::reversed) //reverses the value of key Three. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment