Skip to content

Instantly share code, notes, and snippets.

@kourge
Created June 4, 2014 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kourge/38c1d3a07a5dee9407c0 to your computer and use it in GitHub Desktop.
Save kourge/38c1d3a07a5dee9407c0 to your computer and use it in GitHub Desktop.
Fun with double arrow / hash rocket in Swift
operator infix => { associativity left }
func => <K : Hashable, V>(key: K, value: V) -> (K, V) {
return (key, value)
}
let pairs: (String, Int)[] = [
"e" => 10,
"t" => 7,
"i" => 2
]
@zlangley
Copy link

zlangley commented Jun 5, 2014

This is cool. Do you need associativity? "a" => "b" => "c" doesn't make sense anyway since tuples aren't Hashable.

@kourge
Copy link
Author

kourge commented Jun 5, 2014

Swift seems to have no problem with it if you leave out associativity but every mention of custom infix operators in the docs declares associativity out of convention.

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