CodeSampleX

Пример

collection 1.19.1: Compare two Dart Lists, Maps or Sets by their contents, and use one as a cache key, when == on a collection is identity

Проверенный пример — pub collection 1.19.1: Compare two Dart Lists, Maps or Sets by their contents, and use one as a cache key, when == on a collection is…

sha256:7227421d006842fac6a96b0d2190f4a93f7cbbd5a2ee8a34116cb7c2f7b20d1c

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
2
Заявленная среда dart 3 linux x64 dart 3 dart pub

Среды запусков проверки

Окружение Контракт Этапы Запуск
dart 3 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-14
dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-18

Кейс

HOW
Цель
Compare two Dart Lists, Maps or Sets by their contents, and use one as a cache key, when == on a collection is identity
Пакеты
Символы
  • ListEquality
  • MapEquality
  • SetEquality
  • IterableEquality
  • DeepCollectionEquality
  • DeepCollectionEquality.unordered
  • DeepCollectionEquality.hash
  • groupBy
  • firstWhereOrNull
  • whereNotNull
  • HashMap
Окружение
dart 3
Создан
2026-08-14T13:05:28Z

Контракт

  1. assert two Lists with the same contents are not ==, and neither are two Maps nor two Sets, while package:test's equals matcher deep-compares the same values, nested ones included, and passes
  2. assert a const collection is canonicalized, so const [1, 2] is identical to const [1, 2], that canonicalization is per type argument, and that copying the list loses the equality again
  3. assert ListEquality compares in order while MapEquality and SetEquality do not, their hashes agree where their equals does, and IterableEquality compares a List against a Set
  4. assert ListEquality and MapEquality go exactly one level deep, so nested collections are compared with == and only match when the inner values are const-canonicalized
  5. assert DeepCollectionEquality recurses through nested maps, lists and sets, is already order-insensitive for Sets but not for Lists, that unordered() extends that to Lists as a multiset, and that non-collections fall through to the base equality
  6. assert a Map used as a key in a plain Map only matches the instance it was stored under, so the cache grows and never hits, while a HashMap given DeepCollectionEquality's equals and hash matches a rebuilt key whatever order its literal was written in
  7. assert equal structures produce equal DeepCollectionEquality hashes, that the ordered and unordered hashes track their own equalities, and that a HashMap given equals without hashCode misses 2000 freshly built keys without calling the equals it was given even once
  8. assert groupBy returns exact groups keyed in first-occurrence order, firstWhereOrNull returns null where the SDK's firstWhere throws StateError, and whereNotNull yields the same List<int> as the SDK's nonNulls that deprecates it
  9. assert Dart records compare by value and work as Map keys, but a record holding a List is back to identity

Файлы

  • csx.json
  • lib/equality.dart
  • pubspec.lock
  • pubspec.yaml
  • test/contract_test.dart

Скачать артефакт с исходным кодом (tar.gz)

Исходный сидер

anonymous