Skip to content

Instantly share code, notes, and snippets.

@ennioma
Created February 22, 2018 12:19
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/6ddc0fc5d7173041bf4572455a231d18 to your computer and use it in GitHub Desktop.
Save ennioma/6ddc0fc5d7173041bf4572455a231d18 to your computer and use it in GitHub Desktop.
Update surname
let actor = Actor(name: "George", surname: "Clooney")
let movie = Movie(title: "A beautiful movie", year: "2010", actors: [actor])
print(movie.actors) // [George Clooney]
print(movie.title) // A beautiful movie
let surnameLens = Movie.Lenses.mainActor >>> Actor.Lenses.surname
let updatedMovie = surnameLens.set(movie, "Pitt")
print(updatedMovie.actors) // [Brad Pitt, George Clooney]
print(updatedMovie.title) // A beautiful movie
print(Movie.Lenses.mainActor.get(updatedMovie)) // [Brad Pitt]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment