[Grammer] 26 - Custom Operators

in swift4 •  6 years ago 
  • Custom Operators : prefix, postfix, infix 중 하나를 커스텀
infix operator *+* : MultiplicationPrecedence // 우선순위 그룹 설정
extension Int {
   static func *+*(left: Int, right: Int) -> Int {
      return (left * right) + (left * right)
   }
}
1 *+* 2 + 3 // 7
  • precedencegroup custom
precedencegroup MyPrecedence {
   higherThan: AdditionPrecedence
}
infix operator *+* : MyPrecedence // 우선순위 그룹 설정
extension Int {
   static func *+*(left: Int, right: Int) -> Int {
      return (left * right) + (left * right)
   }
}

1 *+* 2 + 3 // 7
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @gunw! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!