Creating infix operators in Scala

后端 未结 1 1856
情歌与酒
情歌与酒 2021-01-01 19:20

I am trying to translate some of my Haskell code into Scala and I am having difficulty with creating infix operators.

In Haskell say I have this infix operator defin

相关标签:
1条回答
  • 2021-01-01 19:42

    You can define implicit class

    implicit class Iff(val b: Boolean) extends AnyVal {
      def <=>(that: Boolean) = this.b == that
    }
    

    and now you can call it without using new :

    true <=> false // false
    false <=> true // false
    true <=> true  // true
    
    0 讨论(0)
提交回复
热议问题