Last active
August 29, 2015 14:02
-
-
Save philsquared/51d28c8b364a16ed328a to your computer and use it in GitHub Desktop.
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
// Define an optional chaining pipeline operator | |
operator infix |> { associativity left } | |
func |> <T, U>(t: T?, f: (T) -> U? ) -> U? { | |
if let t1 = t { return f( t1 ) } | |
else { return nil } | |
} | |
// some dummy classes and functions to chain together | |
class C { let x = 7 } | |
class B { } | |
class A { } | |
func getB( a : A ) -> B? { return B() } | |
func getC( b : B ) -> C? { return C() } | |
let x = ( A() |> getB |> getC )?.x | |
println("x: \(x)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment