takeFirst method
Returns a list containing first n
elements.
val chars = [1, 2, 3, 4, 5, 6, 7, 8, 9];
print(chars.take(3)) // [1, 2, 3]
print(chars.takeWhile((it) => it < 5) // [1, 2, 3, 4]
print(chars.takeLast(2)) // [8, 9]
print(chars.takeLastWhile((it) => it > 5 }) // [6, 7, 8, 9]
Implementation
List<E> takeFirst(int n) {
var list = this is List<E> ? this as List<E> : toList();
return list.sublist(0, n);
}