[Pitch] Observation (Revised)

The problem is of course not that someone can observe name and awards independently. Some people need this.

The problem is that it is harder for people who observe both to do the correct thing, which is to observe both in one shot.

// Maybe not so great
car.values(for: \.name)
car.values(for: \.awards)
// car.values(for: ???) Nothing for name+awards

// Suggested api
car.track { $0.name }
car.track { $0.awards }
car.track { ($0.name, $0.awards) }
car.track { /* whatever can be built from a car */ }

With a closure argument, you'd make the observation of complex values as easy as the observation of properties. Users are no longer lured by a convenience api into observing individual keypaths, merge the results (and see broken invariants).

1 Like