Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lenses example
let actor01 = Actor(name: "Sharon", surname: "Stone")
let actor02 = Actor(name: "George", surname: "Clooney")
let actor03 = Actor(name: "Ennio", surname: "Masi")
let movie01 = Movie(title: "movie01", year: "1995", actors: [actor01, actor02])
let movie02 = Movie(title: "movie02", year: "2002", actors: [])
Movie.Lenses.mainActor.get(movie01) // -> "Sharon Stone"
Movie.Lenses.mainActor.get(movie02) // -> nil
Movie.Lenses.mainActor.get(Movie.Lenses.mainActor.set(movie01, actor03)) // -> Ennio Masi ✌🏼
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment