Skip to content

Instantly share code, notes, and snippets.

@yycking
Created February 22, 2017 10:25
Show Gist options
  • Save yycking/6daee5e4d0652a7f44a90de531698115 to your computer and use it in GitHub Desktop.
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.)
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
@yycking
Copy link
Author

yycking commented Feb 22, 2017

any way to make my code look like this?

UILabel()
    <| text("pipe")
    <| sizeToFit()
|> self.view.addSubview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment