Skip to content

Instantly share code, notes, and snippets.

@nanoxd
Last active September 22, 2018 16:46
Show Gist options
  • Save nanoxd/028498d411218a0c5d5d4d7f371eace2 to your computer and use it in GitHub Desktop.
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
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