create a postfix operator for any object


/ Published in: Scala
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.