Created
January 7, 2019 14:17
-
-
Save andrevidela/f4571b2f4ea4efc91d5888bf6827e084 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| operator ^^: PowerPrecedence | |
| precedencegroup PowerPrecedence { | |
| higherThan: MultiplicationPrecedence | |
| associativity: right | |
| } | |
| func ^^ <A: Multiplicative> (lhs: A, rhs: Int) -> A { | |
| var a = A.multId | |
| for _ in 0..<rhs { | |
| a = a * lhs | |
| } | |
| return a | |
| // This function is equivalent to | |
| // `return Array(repeating: lhs, count: rhs).reduce(A.multId, *)` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment