Dart Iterable Take() & TakeWhile().

Dart Iterable Take() & TakeWhile().

Take()

  • This method returns an Iterable containing the first count elements from the original Iterable.

TakeWhile()

  • This method returns an Iterable containing the initial elements of the original Iterable as long as the specified condition (test) is true.

Example

void main() {
  var nums = [1, 2, 3, 4, 5];
  var take;
  take = nums.take(4);
  print(take);

  var nums1 = [1, 2, 3, 4, 5];
  var takes;
  takes = nums1.takeWhile((value) => value <= 3);
  print(takes);
}

Output

(1, 2, 3, 4)
(1, 2, 3)

Exited.