Kotlin sequence "skip" first N entries
Asked Answered
B

1

83

How can I "skip" the first N entries of a kotlin sequence/list?

I am looking for the kotlin equivalent of C# LINQ "skip".

Brunk answered 26/4, 2017 at 8:37 Comment(0)
B
131

You are probably looking for the "drop" function known for example from from lodash:

val seq = 1..10

seq.drop(5)
> [6, 7, 8, 9, 10]
Brunk answered 26/4, 2017 at 8:37 Comment(1)
Note that in your example seq is not a Sequence, but an IntRange which is Iterable. Nevertheless drop extension function is available both for Sequence and Iterable.Percy

© 2022 - 2024 — McMap. All rights reserved.