Skip to content

Instantly share code, notes, and snippets.

@dankogai
Last active August 29, 2015 14:02
Show Gist options
  • Save dankogai/64a12fafa7f2ca7bce93 to your computer and use it in GitHub Desktop.
Save dankogai/64a12fafa7f2ca7bce93 to your computer and use it in GitHub Desktop.

Undocumented Swift

Operator Functions

Just like Haskell, operators can be used as a function.

var d = 40
d + 1      // 41
(+)(d, 2)  // 42 

Unlike Haskell, Swift has assignment operators which also works as a function.

(+=)(&d, 2) // d is now 42. Note it is d, &d, not d

Surprisingly this does NOT work. Looks like the assignment operator = is special.

(=)(&d, 42) // Swift complains, "Expected ',' separator"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment