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

Next, import the library:

import 'package:easy_entry/easy_entry.dart';

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);

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([]);

Libraries

easy_entry