Last active
September 7, 2018 10:42
-
-
Save juliancadi/2007221ad69ab13725a16028c6c8f708 to your computer and use it in GitHub Desktop.
Sequence extension with class having generic types
This file contains 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
import Foundation | |
struct SomeType<T> { | |
let property: T | |
} | |
extension Sequence { | |
func doMagic<T>() -> [T] where Element == SomeType<T> { | |
return self.map { $0.property } | |
} | |
} | |
// Use --------- | |
let stringType1 = SomeType(property: "Hello") | |
let stringType2 = SomeType(property: "World") | |
let stringSequence = [stringType1, stringType2] | |
stringSequence.doMagic() | |
let intType1 = SomeType(property: 123) | |
let intType2 = SomeType(property: 456) | |
let intSequence = [intType1, intType2] | |
intSequence.doMagic() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment