Created
February 22, 2017 10:25
-
-
Save yycking/6daee5e4d0652a7f44a90de531698115 to your computer and use it in GitHub Desktop.
pay respect to pipe-forward (|>) operator and Then(Super sweet syntactic sugar for Swift initializers.)
This file contains hidden or 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
infix operator |>: AdditionPrecedence | |
public func |> <T,U>(lhs: T, rhs: (T) -> U) -> U { | |
return rhs(lhs) | |
} | |
public func |> <T>(lhs: T, rhs: inout T) { | |
rhs = lhs | |
} | |
infix operator <|: AdditionPrecedence | |
public func <| <T>(lhs: T, rhs:(T) -> Void) -> T { | |
rhs(lhs) | |
return lhs | |
} | |
UILabel() | |
<| {"pipe" |> $0.text} | |
<| {$0.sizeToFit()} | |
|> self.view.addSubview |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any way to make my code look like this?