Skip to content

Instantly share code, notes, and snippets.

@sbarski
Created June 17, 2014 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbarski/dbf04c04d36b679e4e2b to your computer and use it in GitHub Desktop.
Save sbarski/dbf04c04d36b679e4e2b to your computer and use it in GitHub Desktop.
Playing swift
// 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