Created
January 25, 2015 16:34
-
-
Save potmo/83f33349fa00fa554f22 to your computer and use it in GitHub Desktop.
Piping functions with operator overload
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
import UIKit | |
import Foundation | |
infix operator => { associativity right} | |
// Start with input | |
func => ( left: String, right: (String)->Void ) -> () -> Void { | |
func returnFunc () -> Void | |
{ | |
right(left); | |
} | |
return returnFunc; | |
} | |
// Handling result | |
func => ( left: (String, (String)->Void)-> Void, right: (String)->Void ) -> (String)->() { | |
func returnFunc(result: String){ | |
left(result, right); | |
} | |
return returnFunc; | |
} | |
func addAToEnd(input: String, done: (String) -> Void) -> Void | |
{ | |
let output:String = input + "A"; | |
done(output); | |
} | |
func padWithB(input: String, done: (String) -> Void) -> Void | |
{ | |
let output:String = "B" + input + "B"; | |
done(output); | |
} | |
func stringOutput(result: String) -> Void{ | |
println("The final result was: " + result); | |
} | |
let pipe = "smack" => | |
addAToEnd => | |
addAToEnd => | |
addAToEnd => | |
addAToEnd => | |
padWithB => | |
stringOutput; | |
pipe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment