pub repository
mirror.p-hatan.combuilt_collection
5.1.1Immutable collections based on the SDK collections. Each SDK collection class is split into a new immutable collection class and a corresponding mutable builder class.
Readme
Built Collections for Dart
Introduction
Built Collections are immutable collections using the builder pattern.
Each of the core SDK collections is split in two: a mutable builder class and an immutable "built" class. Builders are for computation, "built" classes are for safely sharing with no need to copy defensively.
Immutable collections work particularly well with immutable values. See built_value.
You can read more about built_collection on medium.
Design
Built Collections:
- are immutable, if the elements/keys/values used are immutable;
- are comparable;
- are hashable;
- use copy-on-write to avoid copying unnecessarily.
See below for details on each of these points.
Recommended Style
A project can benefit greatly from using Built Collections throughout. Methods that will not mutate a collection can accept the "built" version, making it clear that no mutation will happen and completely avoiding the need for defensive copying.
For code that is public to other projects or teams not using
Built Collections, prefer to accept Iterable where possible. That way
your code is compatible with SDK collections, Built Collections and any
other collection implementation that builds on Iterable.
It's okay to accept List, Set or Map if needed. Built Collections
provide efficient conversion to their SDK counterparts via
BuiltList.toList, BuiltListMultimap.toMap, BuiltSet.toSet,
BuiltMap.toMap and BuiltSetMultimap.toMap.
Built Collections are Immutable
Built Collections do not offer any methods that modify the collection. In
order to make changes, first call toBuilder to get a mutable builder.
In particular, Built Collections do not implement or extend their mutable
counterparts. BuiltList implements Iterable, but not List. BuiltSet
implements Iterable, but not Set. BuiltMap, BuiltListMultimap and
BuiltSetMultimap share no interface with the SDK collections.
Built Collections can contain mutable elements. However, this use is not recommended, as mutations to the elements will break comparison and hashing.
Built Collections are Comparable
Core SDK collections do not offer equality checks by default.
Built Collections do a deep comparison against other Built Collections of the same type, only. Hashing is used to make repeated comparisons fast.
Built Collections are Hashable
Core SDK collections do not compute a deep hashCode.
Built Collections do compute, and cache, a deep hashCode. That means they can be stored inside collections that need hashing, such as hash sets and hash maps. They also use the cached hash code to speed up repeated comparisons.
Built Collections Avoid Copying Unnecessarily
Built Collections and their builder and helper types collaborate to avoid copying unless it's necessary.
In particular, BuiltList.toList, BuiltListMultimap.toMap,
BuiltSet.toSet, BuiltMap.toMap and BuiltSetMultimap.toMap do not make
a copy, but return a copy-on-write wrapper. So, Built Collections can be
efficiently and easily used with code that needs core SDK collections but
does not mutate them.
When you want to provide a collection that explicitly throws when a
mutation is attempted, use BuiltList.asList,
BuiltListMultimap.asMap, BuiltSet.asSet, BuiltSetMultimap.asMap
and BuiltMap.asMap.
Features and bugs
Please file feature requests and bugs at the issue tracker.
Changelog
Changelog
5.1.1
- Test fix for new analyzer hint.
5.1.0
- Allow collections with nullable types, for example
BuiltList<T?>. - Allow key/value types to be
dynamic. This can be useful occasionally, and with Dart 2 and null safety it's much harder to usedynamicby accident.
5.0.0
- Stable null safe release.
5.0.0-nullsafety.0
- Migrate to NNBD.
- Deps on
package:collectionandpackage:quiverhave been removed. - Multimap builders no longer have
addAllmethods that accept multimaps from quiver. But, the constructors still work with quiver multimaps.
4.3.2
- Add an
examplefolder with some example code.
4.3.1
- Internal: cleanup for pedantic v1.9.0 lints.
4.3.0
- Add extensions methods:
List.build,Set.build,Map.build,Iterable.toBuiltListandIterable.toBuiltSet. Requires SDK 2.6.0. - Cleanup: remove unnecessary
newandconst.
4.2.2
- Bug fix:
ListMultimapBuilder.[]no longer ignores modifications under some circumstances.
4.2.1
- Bug fix:
ListBuilderfirstandlastsetters can no longer modify the underlying collection.
4.2.0
- Add benchmark for VM and dart2js.
- Stop doing explicit type checks on elements; in Dart 2 these are implied.
- Modify methods on
ListBuilderandSetBuilderthat takeIterableelements so they only iterate over the iterable once. Improves performance when the iterable are slow/lazy.
4.1.0
- Add return val to
SetBuilder.add()to matchSet.add(). - Expand
ListMultimapBuilder: implement[]and add return values toremoveandremoveAll.
4.0.0
- Many changes following Dart 2 improvements to collections:
- Implement
Iterablemethods:cast,followedByandwhereType. - Remove obsolete
Iterablemethod:retype. - Support
orElseinsingleWhere. - Add
BuiltListmethods:+,indexWhere,lastIndexWhere. - Add
ListBuildersetters and getters:first,last. - Add
BuiltMapmethods:entries,map. - Add
MapBuildermethods:addEntries,updateValue,updateAllValues. - Implement Dart 2 methods in internal collections used by
toList,toMapandtoSet.
- Implement
- Add
fromandofconstructors toBuiltList,BuiltMapandBuiltSet. Thefromconstructors, like the current constructors, take collections of any type and check each element. Theofconstructors, like the SDKofconstructors, take a collection of the correct type. This means they can be used for type inference, allowing you to omit the explicit type. - Make
remove,removeAtandremoveLastmethods on builders return values like their SDK collection equivalents.
3.2.0
- Add length, isEmpty and isNotEmpty to ListBuilder, MapBuilder and SetBuilder
3.1.3
- Allow SDK 2.0.0.
3.1.2
- Allow quiver 2.0.0, use test version 1.
3.1.1
- Allow quiver 0.29.
3.1.0
- Implement
followedByonBuiltListandBuiltSet.
3.0.5
- Type fixes for DDC. Stop using a
Mapas aMap<K, V>inMapBuilder.
3.0.4
- Tweaks to tests.
3.0.3
- Allow quiver 0.28.
3.0.2
- Stop using
Function()syntax forSetandMapfactories. It causes problems for the analyzer when using a pre-Dart-2 SDK.
3.0.1
- Improve package description.
3.0.0
- Prepare for Dart 2; add methods that will appear in
Iterable. - Allow quiver 0.27.
2.1.3
- Revert changes for Dart 2; they will be re-released as v3.0.0 as they are break libraries that provide their own implementations of built collections.
2.1.2
- Fix changes for Dart 2.
2.1.1
- Prepare for Dart 2; add methods that will appear in
Iterable.
2.1.0
BuiltSetandBuiltMapnow allow you to specify the underlying collection type. For example, you can construct aBuiltSetusing aSplayTreeSet. This results in a set that is always in sorted order instead of preserving insertion order. Another useful possibility is to use aHashSet, which leads to a random order but improves performance over the default. SeeSetBuilder.withBaseandMapBuilder.withBase.
2.0.0
- Split collection classes into abstract interfaces and concrete, private,
implementations. This allows new implementations of the interfaces. Note that
this change is invisible unless you rely on the exact
runtimeTypeof the collections.
1.6.2
- Fix a bug whereby
ListBuilderandMapBuilderallowed nulls to be introduced viamapandexpand.
1.6.1
- Allow quiver 0.26.
1.6.0
- The addIterable method is now generic. This allows the types of the functions passed in to be inferred.
1.5.0
- Add BuiltIterable interface for when you want to accept a BuiltList or BuiltSet.
1.4.1
- Use real generic syntax, drop comment-based syntax.
1.4.0
- Add operator[] to ListBuilder and MapBuilder for easier inline updates.
1.3.1
- Allow quiver 0.25.
1.3.0
- Widen parameter of BuiltSet.difference and BuiltSet.intersection to
BuiltSet<Object>to match Set.
1.2.0
- Update for Set.difference change in SDK 1.21.0.
- Add
asList,asMap, andasSetto the built collection classes.
1.1.0
- Remove runtime checks that are unnecessary if the project using
built_collection is "strong mode clean", that is, if it has no errors with
strong mode. See note in
README.mdabout strong mode.
1.0.6
- Allow quiver 0.23.
1.0.5
- Strong mode clean.
1.0.4
- Add reference identity check to equals operators.
1.0.3
- Fix factories when iterable generic type is subtype of requested type.
1.0.2
- Add generic type information to map, fold and expand methods.
1.0.1
- Make map operator[] take Object instead of K, as SDK collections do.
- Fix toString for result of toList, toSet, toMap.
1.0.0
- Fix missing generics on some return types.
- Fix BuiltList and BuiltSet "contains" method, should take Object, not E.
- Add removeAll and retainAll methods to SetBuilder.
- Add BuiltList.toBuiltSet() and BuiltSet.toBuiltList().
- Add addIterable methods to Map and Multimap builders.
0.4.0
- Add BuiltSetMultimap.
0.3.1
- Fix "part of" statement.
0.3.0
- Bug fix: fix Iterable "update in place" methods of BuiltList and BuiltSet so they discard original list or set.
- Make keys and values stable for BuiltMap and BuiltMultimap.
- Make repeated builds return identical instances for BuiltList, BuiltMap, BuiltSet.
- Add 'replace' methods.
0.2.0
- Add BuiltListMultimap.
0.1.1
- Fix comments.
0.1.0
- Add build and rebuild methods to BuiltList, BuiltMap, BuiltSet.
- Add update methods to ListBuilder, MapBuilder, SetBuilder.
0.0.1
- Initial version.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add built_collectionpubspec.yaml
name: built_collection
version: 5.1.1
description: >
Immutable collections based on the SDK collections. Each SDK collection class
is split into a new immutable collection class and a corresponding mutable
builder class.
homepage: https://github.com/google/built_collection.dart
environment:
sdk: '>=2.12.0-0 <3.0.0'
dev_dependencies:
pedantic: ^1.4.0
test: ^1.16.0-nullsafety
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2015-04-07T18:10:07.501520Z | Download | d8062b7673f5634780a74b7fe69ed04db5cf189a5d86dc768bbae7eba909ee7f |
| 0.1.0 | 2015-04-17T13:19:04.068060Z | Download | 850338d78d4b3237b91c70a1142121b1198048b12cee1ff932e536200cdae52d |
| 0.1.1 | 2015-04-19T09:53:35.948150Z | Download | 2db50e51f1c6e41fb3fdf1f2b721e1b48f5d94346a5656d6411916c181476038 |
| 0.2.0 | 2015-05-14T08:23:54.797Z | Download | 197d04000f46a497ab9860a2e1d0b80a786abba0ccf05d4391231b97e8981629 |
| 0.3.0 | 2015-05-15T13:35:00.705270Z | Download | 0e1aa4c4e94dbfc3aff7e21e6137c774d27646a61a6db6a138dea410a3d97f8c |
| 0.3.1 | 2015-05-15T15:31:55.283920Z | Download | 8ff9cfb01626af4de55d566c80521489eece1eace1c303f9007af40736e36c29 |
| 0.4.0 | 2015-06-12T06:15:59.628Z | Download | 832254374eaf4444b266a2cc0bf088c0a8fdadcbce2af3ba3d14dc725d3a6017 |
| 1.0.0 | 2015-08-13T09:54:35.792Z | Download | 026261e4588e9d61046eb8c638ccd96e8bdb5a56cfbf794a9683feeef8b6093b |
| 1.0.1 | 2016-02-23T18:22:48.353Z | Download | 9a4bd512ec5d04ffecef1dc3934891342f6708e299f3d3372b6a7a0105e0bf25 |
| 1.0.2 | 2016-03-18T09:33:18.275Z | Download | a673056f99a586b73b5c856bdbf05694b7d439f61b58a6ea3167a29cf360d494 |
| 1.0.3 | 2016-05-18T07:37:19.227Z | Download | dafce4b49e18fc1d2f3bfcec4f1f9e728b89e923f5b604364be613def1a15aa1 |
| 1.0.4 | 2016-07-15T14:52:03.317Z | Download | b5f22eeeda99070c4a8bd986554e5ab9e4f0e6fba210071d5a75f55859fb22f3 |
| 1.0.5 | 2016-09-15T14:50:05.295Z | Download | 4d966c534599d1905538693c5aafb4eeda3a5204a6c5893b675ea34ea9703366 |
| 1.0.6 | 2016-10-19T07:47:34.817Z | Download | 6bd2aa97543374f67f4e3d3d9c6678c88b9da8b9c3ecc48358e300403192fbf3 |
| 1.2.0 | 2016-11-11T13:21:52.500Z | Download | de439c97284649191b80e8318c83c04363a78a231317a9abbccc4f85b2877da1 |
| 1.3.0 | 2016-12-22T14:48:51.718Z | Download | a08ba03f770460ebbb11421f4fe48cf4febee70f8cdcc33edad3e1b755b449a0 |
| 1.3.1 | 2017-04-07T12:13:57.279032Z | Download | 7ad196d2a998ca8e346a8bc5a5b3e97e7ba24990b9c7d4156384627362024059 |
| 1.4.0 | 2017-04-11T14:51:47.173955Z | Download | 37ee3865b46804ac6a7a61c0170e70c9461b1a15ca1d8fac4ba2bff2d38dd6e9 |
| 1.4.1 | 2017-06-20T10:47:45.305410Z | Download | 6cd1e573d52de4fecf02d1f4a04c056039d0a21dbec12eac18455cf45c8e27bf |
| 1.5.0 | 2017-07-12T10:39:35.742973Z | Download | d8ad909707e10d80268c652992bec250503b4d30c96a40e4f7814de3c7b43ef4 |
| 1.6.0 | 2017-10-17T15:26:36.214370Z | Download | 5c3ef5957fdc83aef01f63fe0e9ae40d7f4b7904e18c470b134d93cd1a425399 |
| 1.6.1 | 2017-11-09T09:16:04.595087Z | Download | c63724beb3944133b5b7ec56358f000111bdbfa2f52ea34605f838c35dd95d87 |
| 1.6.2 | 2017-11-16T12:55:14.327475Z | Download | aff2c3bfdf110597c3c9a7c4d1d5dfd4da7d72430b4915aa2e612c233809d91e |
| 2.0.0 | 2017-11-20T15:37:24.675968Z | Download | 4cd9a06926896d7069efefa545f2c65bd2b176ff64c0b5bf2957a1fe39536ba6 |
| 2.1.0 | 2017-12-04T12:09:06.704154Z | Download | 7d1306375328ab49f4ea148b866141f1a931ff97a0292b33eb3255d13fb24566 |
| 2.1.1 | 2017-12-21T14:24:03.112784Z | Download | d781ae3c7dec12fb37c02eb552b66c7c3ea75433198bfcd0069046099b2d6ad5 |
| 2.1.2 | 2017-12-21T15:02:24.827648Z | Download | a405a8f179f8665d01e0078e1ae2fccbd37898f64a5964f5108b86774472dc07 |
| 2.1.3 | 2018-01-08T08:39:38.777653Z | Download | 0cf3a04c62ea9142acc056e552bfa73df74324021b06e1fd8ba76bf943297cb4 |
| 3.0.0 | 2018-01-08T08:52:04.316616Z | Download | 3fa561eb20d28e87b406d478712abc920706f268812e60b46b3a04081ce66ae9 |
| 3.0.1 | 2018-01-16T08:14:34.769542Z | Download | e476e4314004e508664375ec85295e31a9916d6b9cd1ec8a054f0526dd7e367f |
| 3.0.2 | 2018-01-23T09:35:53.446079Z | Download | 5432d6b800f952ceef7ab690acec17e61bc4ff9b9fe7d524f9ddae7193b04b30 |
| 3.0.3 | 2018-01-29T10:59:12.738812Z | Download | 6390f84e75ef80e74f0ce9988a386e0319627d862ab382ef386e4b07143e52f7 |
| 3.0.4 | 2018-01-31T12:09:30.428922Z | Download | 9780fa3ceb6fdaa4ebdc060df9dac0c4bfe3178676a8699bcaa919ca7cf08983 |
| 3.0.5 | 2018-02-18T15:26:33.432476Z | Download | 46e721c39eb903f1c5a8c1565eba76db9b625652b934dac7545ca2df4685ef5e |
| 3.1.1 | 2018-03-26T13:34:51.287754Z | Download | c2686e3691b5cc9a267955417bea9d1f14c99a4848395bf21e0cbf03490c227e |
| 3.1.2 | 2018-07-23T12:02:28.638465Z | Download | acbf985bd3a4229c1e4ca2e29bcb12f0d2474e42fd9da0c2c38651b810426e9b |
| 3.1.3 | 2018-07-23T15:01:36.694168Z | Download | c587bd02eb543325e790f5bd8fc237e8b3ef4268713f9673cac1bf90ff720b81 |
| 4.0.0 | 2018-08-20T15:48:07.319903Z | Download | 25c0ee658dc59056fed086211f936a256b185adb355cab7da6a8f1d57f5dc4e9 |
| 4.1.0 | 2018-12-03T14:48:52.046182Z | Download | 3c8557b03e8cbb912b76facc6ebf4b1f0ae3db0b40b4a4518f37ddc4a64a0916 |
| 4.2.0 | 2019-04-02T08:06:39.140092Z | Download | 57eb973acf51556bd71521a4bba7d48f3f0fe325bfb6e9ce47037df317f53b4b |
| 4.2.1 | 2019-05-06T13:33:56.470527Z | Download | a9f38c82eb6283074071f7e98af32474ed4bf8f1ab1ae8be45f084ba48fba99d |
| 4.2.2 | 2019-05-12T19:36:24.486541Z | Download | eb1aea105400a724bc75e4eb7749e9cf4be6d281a1e7e49cf4c57ad8610fca2a |
| 4.3.0 | 2019-11-15T10:24:14.992201Z | Download | 3d06fdda7058507c0ac8df084871dfdb9fe86fa7a80bdcee3d4e4e3a4c1ba5c9 |
| 4.3.1 | 2019-12-31T15:42:20.584303Z | Download | aad438ced10134f00b17d150bcf094a26caf9c44c9bf05d2cf68e5ff6654d82c |
| 4.3.2 | 2020-01-01T16:30:21.201029Z | Download | 4b741b723310592422031210f77c9707ad1e5ea2a061eb21a8b5d8308a8b92be |
| 5.0.0-nullsafety.0 | 2020-11-17T10:35:34.510180Z | Download | 7fc151b3b10334d6c471afe7024b5cffef66f3e439f1a0c4c9ca1f86ee14c7b9 |
| 5.0.0 | 2021-02-09T09:37:24.946427Z | Download | f5a2a975d3da1ca46579d2f173bea1c766f0044cff40889c8df8009bf6ea0d0c |
| 5.1.0 | 2021-06-11T09:29:30.705602Z | Download | 604f0cc0937ff65e7eef35996e60a2452499c4d76940324949ff20a92421f3d2 |
| 5.1.1 | 2021-09-03T07:47:53.359281Z | Download | 376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100 |
| 5.1.2 | 2026-09-28T09:25:53.103645Z | Download | 44922ecebd8e3d0cef743dadd3b54df4e87e2a4c52a29465a1872aa9e192caa8 |
| 6.0.0 | 2026-10-26T11:47:15.999461Z | Download | 68c430bce63c47a00d7c978545777d2f6315bb1dbbb098d4f60cfd3148b8bc61 |
Dependencies
No direct dependencies declared.