Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@juliancadi
Last active September 7, 2018 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliancadi/2007221ad69ab13725a16028c6c8f708 to your computer and use it in GitHub Desktop.
Save juliancadi/2007221ad69ab13725a16028c6c8f708 to your computer and use it in GitHub Desktop.
Sequence extension with class having generic types
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