Skip to content

Instantly share code, notes, and snippets.

@macbaszii
Created August 24, 2015 07:50
Show Gist options
  • Select an option

  • Save macbaszii/6f2c1fa96d22b00ac06f to your computer and use it in GitHub Desktop.

Select an option

Save macbaszii/6f2c1fa96d22b00ac06f to your computer and use it in GitHub Desktop.
extension Optional {
func apply<U>(f: (T -> U)?) -> U? {
switch f {
case .Some(let someF): return self.map(someF)
case .None: return .None
}
}
}
extension Array {
func apply<U>(fs: [Element -> U]) -> [U] {
var result = [U]()
for f in fs {
for element in self.map(f) {
result.append(element)
}
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment