mattgallagher / CwlSignal

A Swift framework for reactive programming.
ISC License
303 stars 33 forks source link

Add support for key paths? #23

Closed zoul closed 6 years ago

zoul commented 6 years ago

Key paths would make a nice addition to the API, for example on Signal:

func filterMap<U>(_ path: KeyPath<OutputValue, U?>) -> Signal<U> {
    return filterMap { $0[keyPath: path] }
}

Hopefully we will eventually get some kind of keypath ↔︎ function equivalence on the language level, but until then, would you consider adding the overloads for key paths where appropriate?

mattgallagher commented 6 years ago

Sure. I'll try to do this later this week.

mattgallagher commented 6 years ago

Wow, my ability to predict the future is terrible. In any case... I've added keyPath in commit 7e67484b7d49e7fa7b67e29c217b9b602e13332f

If you also need to filter optionals, you can follow with compact().