O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lenses

We will use lenses to modify our Todo item. Each of the following lenses will be used to modify a part of the Todo item:

struct Lens<Whole, Part> {     let get: (Whole) -> Part     let set: (Part, Whole) -> Whole } let todoNameLens: Lens<Todo, String> = Lens(     get: { $0.name},     set: {         Todo(todoId: $1.todoId,              name: $0,              description: $1.description,              notes: $1.notes,              completed: $1.completed,              synced: $1.synced,              selected: $1.selected) }) let todoDescriptionLens: Lens<Todo, String> = Lens(     get: { $0.description},     set: {         Todo(todoId: $1.todoId,              name: $1.name,              description: $0,              notes: $1.notes,              completed: $1.completed,              synced: $1.synced,              selected: $1.selected) }) let todoNotesLens: Lens<Todo, String> = Lens(     get: { $0.notes!}, 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required