partition 1.0.1 copy "partition: ^1.0.1" to clipboard
partition: ^1.0.1 copied to clipboard

A library for partitioning iterables based on predicates. By default, partitioning happens lazily over the source iterable but eager partitioning can be used by setting the lazy parameter or using the [...]

example/partition_example.dart

import 'package:partition/partition.dart';

void main() {
  final source = Iterable.generate(10, (i) {
    print('Generating $i');
    return i;
  });

  // Partition lazily. Results in two iterations over source.
  var partitioned = source.partition((i) => i.isEven);
  print(partitioned.matching);
  print(partitioned.nonMatching);

  // Partition eagerly. Results in one iteration over source.
  partitioned = source.partition((i) => i.isEven, lazy: false);
  print(partitioned.matching);
  print(partitioned.nonMatching);

  // Shorthand for `lazy: false`.
  partitioned = source.partitionNow((i) => i.isEven);
  // The result is a decorated list, so we don't *have* to use
  // matching/nonMatching getters to access the underlying iterables.
  print(partitioned[0]);
  print(partitioned.last);
}
2
likes
130
pub points
48%
popularity

Publisher

verified publisheralexmeuer.com

A library for partitioning iterables based on predicates. By default, partitioning happens lazily over the source iterable but eager partitioning can be used by setting the lazy parameter or using the partionNow extension method.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection

More

Packages that depend on partition