(re...">

Scala implicit return problem

Using Scala "2.10.4" I have an implicit definition like this:

implicit class MyImplicits(val s: S) {
  def ==>(relation: W):Option[List[S]] = {
    getRelation(s,relation)
  }
}

      

when i want to use it, after fine works:

import MyImplicits
val list1 = s ==>(w)
val value = list1.get

      

But when I write this, I get the error:

import MyImplicits
val value = s ==>(w).get


Error:(56, 67) value get is not a member of MyImplicits
      val value = s ==>(w).get
                            ^

      

What is the reason for this error and still solve it?

+3


source to share


2 answers


This is because it applies get

to to (w)

and not to the entire expression.

Try the following:



val value = (s ==>(w)).get

      

+4


source


As Ashalind already explained, period has a higher precedence than the ==> operator. You can work around it with a parenthesis, or use it get

as a postfix operator:



val value = s ==> w get

      

0


source







All Articles