Skip to content

Instantly share code, notes, and snippets.

@ahernandezlopez
Last active March 21, 2018 07:20
Show Gist options
  • Save ahernandezlopez/ec685f9efcf78d73a33d to your computer and use it in GitHub Desktop.
Save ahernandezlopez/ec685f9efcf78d73a33d to your computer and use it in GitHub Desktop.
Useful for SequenceType upcasting, i.e. for upcasting "array of protocol implementers" to array of protocol
extension SequenceType {
func upcast<T, U where Self.Generator.Element == T>() -> [U] {
return flatMap {$0 as? U}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment