Created
June 17, 2014 10:02
-
-
Save sbarski/dbf04c04d36b679e4e2b to your computer and use it in GitHub Desktop.
Playing swift
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
// Playground - noun: a place where people can play | |
operator infix |> { | |
associativity left | |
} | |
operator infix <| { | |
associativity right | |
} | |
func |> <L, R>(left: L, right: L -> R) -> R { | |
return right(left) | |
} | |
func <| <L, R>(left: R -> L, right: R) -> L { | |
return left(right) | |
} | |
func unique<T:Hashable>(array: Array<T>) -> Array<T> { | |
var filter = Dictionary<T, Bool>() | |
var result = Array<T>() | |
for i in 0..array.count { | |
if let elem = filter[array[i]] { | |
continue | |
} else { | |
filter[array[i]] = true | |
result.append(array[i]) | |
} | |
} | |
return result | |
} | |
[7,2,3,4,5] |> sort |> unique |> toString | |
toString <| sort <| [7,2,4,4,5] | |
## http://www.mseri.me/piping-with-swift/ | |
## http://www.kevinberridge.com/2012/12/neat-f-pipe-forward.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment