Posted By

pligor on 10/05/12


Tagged

operator postfix


Versions (?)

create a postfix operator for any object


 / Published in: Scala
 

create a postfix operator for any object combining a class and an implicit

  1. class MyClass(x: Int) {
  2. def myPostfixOperator: Boolean = x > 0;
  3. }
  4. implicit def int2myclass(x: Int) = new MyClass(x);
  5.  
  6. val y: Boolean = 1.myPostfixOperator; //this is true

Report this snippet  

You need to login to post a comment.