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?
Coming to list, tail() method is used to skip the first element of the list.
It provide us hasNext() and next() method to work with collection elements. The basic syntax to define the iterate in scala is as follows; valiterate_name = Iterator(value1, value2, value3, so on ....) In this way, we can define an iterate in scala.
(1 to 5).drop(3).foreach(println(_))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With