Skip to content

Instantly share code, notes, and snippets.

@ennioma
Last active February 22, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ennioma/0feb3b0e43f85cf84a91a19692c0c10f to your computer and use it in GitHub Desktop.
Save ennioma/0feb3b0e43f85cf84a91a19692c0c10f to your computer and use it in GitHub Desktop.
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