Skip to content

Instantly share code, notes, and snippets.


ennioma/updateSurname.swift Secret

Created Feb 22, 2018
What would you like to do?
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