April 2017
Intermediate to advanced
316 pages
9h 33m
English
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!}, Read now
Unlock full access