Skip to content

Instantly share code, notes, and snippets.

@Qata
Created May 30, 2019 00:39
Show Gist options
  • Save Qata/46bc0c4bb0272cb53660d460c617a691 to your computer and use it in GitHub Desktop.
Save Qata/46bc0c4bb0272cb53660d460c617a691 to your computer and use it in GitHub Desktop.
extension Optional {
func filter(_ isIncluded: (Wrapped) throws -> Bool) rethrows -> Optional<Wrapped> {
switch self {
case let value? where try isIncluded(value):
return value
default:
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment