collection_ext 1.0.0 copy "collection_ext: ^1.0.0" to clipboard
collection_ext: ^1.0.0 copied to clipboard

A set of useful extension methods for Dart collections, designed for the purpose of making it easier to write functional-programming-styled, concise Dart code.

collection_ext #

Pub Check Status Code Coverage MIT

A set of extension methods for Dart collections, designed for the purpose of making it easier to write concise, functional-programming-styled Dart code.

Working on an Iterable for example, with collection_ext, we can write:

iterable.forEachIndexed((i, x) => /* use index i & element x */)

instead of:

var i = 0;
for (var x in iterable) {
  // use index i & element x
  i++;
}

Usage #

Import all extension methods at once:

import 'package:collection_ext/all.dart';

Column(
  children: getItems()
    .nonNull
    .mapIndexed((i, item) => Text("#$i ${item.title}"))
    .asList(),
)

Or you can import the needed module only, for example:

import 'package:collection_ext/iterables.dart';

final diff = [2, 4, 6].foldRight(0, (x, acc) => x - acc);

Nullability #

All extension methods of Iterables & Maps are null-safe. For example:

Iterable itr;
assert(itr.sum() == 0);

Map map;
assert(map.none((k, v) => true) == true);

See nullability tests for more details.

Available Modules #

👉 See API Docs for more details

I'm working on more useful extensions, PRs are welcome! 🍻🖖

17
likes
150
pub points
84%
popularity

Publisher

verified publisherxinthink.com

A set of useful extension methods for Dart collections, designed for the purpose of making it easier to write functional-programming-styled, concise Dart code.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

tuple

More

Packages that depend on collection_ext