easy_entry 1.0.0
easy_entry: ^1.0.0 copied to clipboard
A simple, readable and concise way to deal with modifying, inserting and removing Map entries in Dart.
A simple, readable and concise way to deal with modifying, inserting and removing Map entries in Dart.
Inspired on Rust's Entry API.
Usage #
Add easy_entry
to our dependencies in pubspec.yaml
:
dependencies:
easy_entry: ^1.0.0
copied to clipboard
Next, import the library:
import 'package:easy_entry/easy_entry.dart';
copied to clipboard
Get a map's entry #
Use the .entry(key)
method on a map to get an entry:
final map = <int, List<String>>{};
map.entry(10);
copied to clipboard
Then, you can perform operations on your entry to modify, insert or remove it from the map:
final items = map
.entry(10)
.retainIf((value) => value.isNotEmpty)
.andModify((value) => value.add('Another Item'))
.orInsert([]);
copied to clipboard