Last active
August 29, 2015 14:23
-
-
Save sketchytech/6de4f2ba0afe2df4f308 to your computer and use it in GitHub Desktop.
Custom Operator >>>
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
typealias StringGarbler = String -> String | |
infix operator >>> { associativity left } | |
func >>> (lhs:StringGarbler,rhs:StringGarbler) -> StringGarbler { | |
return { | |
s in rhs(lhs(s)) | |
} | |
} | |
func rev() -> StringGarbler { | |
return {str in String(str.characters.reverse())} | |
} | |
func dropper() -> StringGarbler { | |
return {str in String(dropFirst(str.characters)) } | |
} | |
let stringGarbler = dropper() >>> rev() | |
stringGarbler("Hello Swift") // "tfiwS olle" | |
let stringGarbler2 = rev() >>> dropper() | |
stringGarbler2("Hello Swift") // "fiwS olleH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment