Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions content/dart/concepts/queue/terms/removeWhere/removeWhere.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
Title: '.removeWhere()'
Description: 'Removes all elements from a queue that satisfy a given condition.'
Subjects:
- 'Computer Science'
- 'Code Foundation'
Tags:
- 'Collection'
- 'Dart'
- 'Methods'
- 'Queues'
CatalogContent:
- 'learn-dart'
- 'paths/computer-science'
---

The **`.removeWhere()`** method removes all elements from a `Queue` that return `true` for a specified condition. The queue is modified in place.

## Syntax

```pseudo
queue.removeWhere(test)
```

**Parameters:**

- `test` (bool Function(E element)): A function that returns `true` for elements that should be removed from the queue.

**Return value:**

This method returns `void`. The original queue is updated by removing all matching elements.

## Example: Removing elements from a queue based on a condition

In this example, `.removeWhere()` is used to remove all tasks from a queue that contain the word "write", updating the queue in place:

```dart
import 'dart:collection';

void main() {
Queue<String> tasks = Queue.from([
'write code',
'review pull request',
'fix bugs',
'write tests'
]);

// Remove all tasks that contain the word 'write'
tasks.removeWhere((task) => task.contains('write'));

print(tasks);
}
```

The output of this code is:

```shell
{review pull request, fix bugs}
```