checkIterableEqual<T extends Iterable> static method

T checkIterableEqual<T extends Iterable>(
  1. T? iterable,
  2. T match, {
  3. bool checkOrder = false,
  4. String? name,
})

Throws if iterable is null, or if the content of iterable does not equal match.

If name is supplied, it is used as the parameter name in the error message.

Returns the iterable if it is not null and if its content equals match.

Implementation

static T checkIterableEqual<T extends Iterable<dynamic>>(
  T? iterable,
  T match, {
  bool checkOrder = false,
  String? name,
}) {
  final nonNullIterable = ArgumentError.checkNotNull(iterable);

  final equality = checkOrder
      ? const DeepCollectionEquality()
      : const DeepCollectionEquality.unordered();
  if (equality.equals(nonNullIterable, match)) return nonNullIterable;

  throw ArgumentErrorUtils._value(
    nonNullIterable,
    name: name,
    message:
        "${name ?? "The iterable"} does not have the same content as match",
    extraMessage: "\nmatch:\n${match.join("\n")}\n\n"
        "${name ?? "iterable"}:\n${nonNullIterable.join("\n")}",
  );
}