Skip to content

Instantly share code, notes, and snippets.

@wess
Last active April 22, 2017 14:32
Show Gist options
  • Select an option

  • Save wess/4ee7bcb233f6009a1e3506f02c4bfda0 to your computer and use it in GitHub Desktop.

Select an option

Save wess/4ee7bcb233f6009a1e3506f02c4bfda0 to your computer and use it in GitHub Desktop.
func decorate(func) {
func wrapper(name:String) {
return "<p>\(func(name))</p>"
}
return wrapper
}
@decorate
func getText(name:String) {
return "Hello there \(name), how are you?"
}
let x = getText("Erica")
print("RESULT: \(x)")
// RESULT: <p>Hello there Erica, how are you?</p>
@erica
Copy link
Copy Markdown

erica commented Apr 13, 2016

infix operator >>> { associativity left }
public func >>><T, U>(x: T, f: T -> U) -> U {
    return f(x)
}

func getText(name:String) -> String {
    return "Hello there \(name), how are you?"
}

func paragraphize(text: String) -> String {
    return "<p>\(text)</p>"
}

print(getText("erica") >>> paragraphize)

@fpillet
Copy link
Copy Markdown

fpillet commented Apr 13, 2016

func decorate(text:String) -> String {
    return "<p>\(text)</p>"
}

func getText(name:String) -> String {
    return "Hello there \(name), how are you?"
}

let x = getText("Erica")
print("RESULT: \(decorate(x))")

@srikantviswanath
Copy link
Copy Markdown

@fpillet: With utmost respect - No shit sherlock

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