compilation - scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found -
Compiling this code in scale 2.7.6:
def flatten1 (L: List [any]): list [any] = l.flatten
I get an error:
parameter type (any) = any The underlying argument matches & gt; Iterable [Any] got
Why?
If you have list (1, 2, 3, 4, 5)
In the "flatten" list (1, 2, list (3,4), 5) you are expecting to be able to,
, then you need something like:
built-in def any2iterable [A] (A: A): Iterable [A] = some (A)
with list:
Val inventory: list [alt [int]] = list (1, 2, list (3,4), 5) conversion to print / print (list.flatten (IRR => IRR)) // list ( 1, 2, 3, 4, 5)
Edit : The answer was as long as the OP did not clarify his question in a comment on Mitch's answer
You what are you expecting when you leave Flaton
a list [int]
? Do you want to add the function int
s to list
? If so, you should see the new execution functions in 2.8.x :
val list = list (1, 2, 3) println (list.sum) ) // 6
Comments
Post a Comment