[Grammer] 26 - Custom Operators

in #swift46 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
Sort:  

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!

Coin Marketplace

STEEM 0.13
TRX 0.23
JST 0.032
BTC 83764.46
ETH 2094.28
USDT 1.00
SBD 0.63