Skip to main content

value_group 0.1.0 copy "value_group: ^0.1.0" to clipboard
value_group: ^0.1.0 copied to clipboard

An ordered, immutable group that distinguishes zero, one, and multiple values by type.

Value Group #

Use an ordered collection when your code handles zero, one, and multiple values differently. Dart pattern matching makes those cases explicit.

import 'package:value_group/value_group.dart';

final selected = Group<String>.from(['A', 'A', 'B']);
const empty = Group<String>.empty();
final group = empty.merge(other: selected, distinct: true);

final label = switch (group) {
  EmptyGroup<String>() => 'None',
  SingleGroup<String>(:final value) => value,
  MultipleGroup<String>(:final values) => values.join(', '),
}; // A, B

Pass a ValuedGroup<T> when a function requires at least one value. Its first getter is always defined. Construct it from an iterable with ValuedGroup.from, which rejects empty input.

The constructors take a shallow snapshot of the iterable in one pass. The values list is unmodifiable. Group equality compares values in order and includes duplicate counts.

An ordinary merge appends the right group and preserves duplicates. Set distinct: true to keep the first occurrence of each value according to its equality and hash code. This works for both operands even when one is empty. The result is classified by its final size.

0
likes
150
points
0
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An ordered, immutable group that distinguishes zero, one, and multiple values by type.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

equatable

More

Packages that depend on value_group