mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 02:19:09 +02:00
v1.1.4
- Added `unique` extension for Lists Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 1.1.4
|
||||
|
||||
- Added the `unique` extension for `List` objects.
|
||||
|
||||
## 1.1.3
|
||||
|
||||
- Removes `Color` extension due to an incompatibility with Flutter. Sorry, @rania-run!
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
library arcane_helper_utils;
|
||||
|
||||
export "package:arcane_helper_utils/src/extensions/date_time.dart";
|
||||
export "package:arcane_helper_utils/src/extensions/list.dart";
|
||||
export "package:arcane_helper_utils/src/extensions/string.dart";
|
||||
export "package:arcane_helper_utils/src/extensions/string_jwt.dart";
|
||||
export "package:arcane_helper_utils/src/utils/json_converter.dart";
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
extension Unique<E, Id> on List<E> {
|
||||
List<E> unique([Id Function(E element)? id, bool inplace = true]) {
|
||||
final Set ids = {};
|
||||
final List<E> list = inplace ? this : List<E>.from(this);
|
||||
list.retainWhere((x) => ids.add(id != null ? id(x) : x as Id));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: arcane_helper_utils
|
||||
description: Provides a variety of helpful utilities and extensions for Flutter
|
||||
and Dart.
|
||||
version: 1.1.3
|
||||
version: 1.2.0
|
||||
repository: https://github.com/hanskokx/arcane_helper_utils
|
||||
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
||||
|
||||
|
||||
Reference in New Issue
Block a user