Last active
September 22, 2018 16:46
-
-
Save nanoxd/028498d411218a0c5d5d4d7f371eace2 to your computer and use it in GitHub Desktop.
[Optional+KeyPathMap] Maps an optional value to a property on the object using a keyPath. #swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional { | |
public func map<T>(_ keyPath: KeyPath<Wrapped, T>) -> T? { | |
return map({ $0[keyPath: keyPath] }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment