Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala implicit return value issue

Tags:

scala

Using Scala "2.10.4", I have a 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, following works fine:

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

But when I write this I get 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 is there anyway to solve it?

like image 562
Omid Avatar asked Apr 21 '26 15:04

Omid


1 Answers

That's because it applies get to (w) rather than to the whole expression.

Try this:

val value = (s ==>(w)).get
like image 65
Ashalynd Avatar answered Apr 26 '26 00:04

Ashalynd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!