Dart by Example: Queue

  1. import 'dart:collection';
  2. main() {
  3. // Queues are optimized for adding to the head or tail
  4. // Items cannot be accessed by their index.
  5. var q = new Queue.from([300, 200, 100, 500]);
  6. // Queues implement Iterable:
  7. print(q.takeWhile((i) => i > 100));
  8. // Consuming a queue
  9. while(q.first > 100) {
  10. q.removeFirst();
  11. }
  12. print(q);
  13. }
  14.  
  1. $ dart queue.dart
  2. (300, 200)
  3. {100, 500}

by @jryanio | source | license