- Added `unique` extension for Lists

Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
Hans Kokx
2024-11-04 17:00:50 +01:00
parent 9f8d85f543
commit 92133b2e28
5 changed files with 34 additions and 1 deletions
+20
View File
@@ -15,6 +15,7 @@ providing utility functions and extensions that simplify common tasks.
class, making it easier to format dates and calculate differences.
- **String Extensions**: Enhances the `String` class by adding new methods for
common transformations and checks, including JWT parsing.
- **List Extensions**: Adds a new `unique` operator for filtering `List` items.
## Getting Started
@@ -330,6 +331,25 @@ objects:
Additionally, the `CommonString` class provides a quick shortcut to common
strings, such as punctuation marks that are otherwise cumbersome to find or type.
### List Extensions
The following extensions have been added to the `List` object:
- `unique([Id Function(E element)? id, bool inplace = true])`: Filters a list
by a given element, returning only non-duplicate values. Can return either a
new `List` or filter the existing list by specifying the `inplace` option.
```dart
final List<String> myList = [
Item(value: "Hello"),
Item(value: "Hello"),
Item(value: "World"),
Item(value: "World"),
];
myList.unique((item) => item.value);
// [Item(value: "Hello"), Item(value: "World")]
## Contributing
Contributions are welcome! Feel free to fork the repository and submit pull