From the docs for the take method on Map :
Selects the first n items.
Note: may return different results for different runs, provided that the base collection type is ordered.
In the case of maps, the collection is not ordered, so do not expect to receive the first n elements - in fact, the concept of the first n elements does not even exist for mappings.
But take will provide you with the first few n elements, and it looks like this is what you want:
scala> Map('a -> 1, 'b -> 2, 'c -> 3).take(2) res1: scala.collection.immutable.Map[Symbol,Int] = Map('a -> 1, 'b -> 2)
In this case, you need to get two elements that are included in the definition, but do not count on it.
source share