SE-0395: Observability

I remember frequently relying on the initial value option in KVO. I'm surprised that's not coming over. However, I think it might be possible to prepend the initial value by chaining an iterator that emits the current value and then ends to the iterator produced by object.values(for: \.someProperty).

I think that could look like this using the async algorithms package

Task {
  for await value in chain([object.someProperty].async, object.values(for: \.someProperty)) {
    // Really important processing of the value
  }
}

It does seem to have been a common enough use case (admittedly anecdotally) from the KVO days, though, that it could be considered for 1st class feature in this system.

2 Likes