Skip to content

Instantly share code, notes, and snippets.

@andrevidela
Created January 7, 2019 14:17
Show Gist options
  • Select an option

  • Save andrevidela/f4571b2f4ea4efc91d5888bf6827e084 to your computer and use it in GitHub Desktop.

Select an option

Save andrevidela/f4571b2f4ea4efc91d5888bf6827e084 to your computer and use it in GitHub Desktop.
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