Skip first N elements in scala iterable

em70 picture em70 · Mar 1, 2012 · Viewed 12.4k times · Source

I'd like to know if scala includes a way to skip the first N elements of an iterable, so that for instance

(1 to 5).WHATIWANT(3).foreach(println(_))

would print only 4 and 5.

I understand there's slice, but if the length of the sequence can't be obtained in advance, like in my case, that's not gonna do.

Ideas?

Answer

Eastsun picture Eastsun · Mar 1, 2012
(1 to 5).drop(3).foreach(println(_))