I want to enhance all Iterable
s with some custom code.
For this I wrote the following:
implicit class RichIterable[A, B <: Iterable[A]](b: B) {
def nonEmptyOpt: Option[B] = if (b.nonEmpty) Some(b) else None
}
Now, when I want to use this method on a List
that definitely is a subclass of Iterable
like so
List(1, 2, 3).nonEmptyOpt
I get
value nonEmptyOpt is not a member of List[Int]
How can I resolve this?
RichIterable[A, B[_] <: Iterable[_]](b: B[A]) {...
– Boatright