Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Array get its toList method

Tags:

scala

Through searches, I understand the way (or, a way) to convert an Array to a List is like so:

val l = Array(1, 2, 3).toList

But not only can I not find the toList method in Array's API docs, I can't find it in anything that seems to be an ancestor or inherited trait of Array.

Using the newer 2.9 API docs, I see that toList exists in these things:

ImmutableMapAdaptor ImmutableSetAdaptor IntMap List ListBuffer LongMap 
MutableList Option ParIterableLike PriorityQueue Stack StackProxy 
StreamIterator SynchronizedSet SynchronizedStack TraversableForwarder 
TraversableOnce TraversableOnceMethods TraversableProxyLike

But I can't understand how toList gets from one of these to be part of Array. Can anyone explain this?

like image 644
dino Avatar asked Mar 11 '11 21:03

dino


1 Answers

toList and similar methods not natively found on Java arrays (including our old favourites, map, flatMap, filter etc.) come from s.c.m.ArrayOps, which arrays acquire via implicit conversions in scala.Predef. Look for implicit methods whose names end with ArrayOps and you'll see where the magic comes from.

like image 89
Alex Cruise Avatar answered Sep 28 '22 08:09

Alex Cruise