David Morgan ☯
2015-04-10 10:38:23 UTC
Hi everyone,
http://www.dartdocs.org/documentation/built_collection/0.0.1/index.html#built_collection/built_collection
I'm pleased to announce a new open source library for those who like a bit
of immutability in their collections.
The link has lots more info, but the short of it is: the library provides
new types splitting the SDK collection interfaces in half:
+ List --> BuiltList (immutable) and ListBuilder (mutable)
+ Set --> BuiltSet (immutable) and SetBuilder (mutable)
+ Map --> BuiltMap (immutable) and MapBuilder (mutable)
Code example:
var list = new BuiltList<int>([1, 2, 3]);
var updatedList = (list.toBuilder()..add(4)..add(5)).build();
var updatedMoreList = (updatedList.toBuilder()..where((x) => (x >
2))).build();
And a few nice points:
MyClass(this.builtList); // no need to copy defensively, it's immutable!
if (builtList1 == builtList2) { ... // deep comparison
var lists = new Set<BuiltList<int>>(); // deep hashCode, can be used in
sets/maps
new BuildList<int>([null]); // throws, nulls aren't allowed
Background:
I work at Google on a project that uses Dart, rather than the Dart team
itself. We've found this approach to collections to be very useful in
building immutable data types to represent UI state and for RPCs. We
decided to rewrite the custom collections we were using for open source
release in the hope that others would find them useful. So, enjoy :) ...
and please do provide feedback, to me directly or on the github issue
tracker: https://github.com/google/built-collection-dart
Regards
Morgan
http://www.dartdocs.org/documentation/built_collection/0.0.1/index.html#built_collection/built_collection
I'm pleased to announce a new open source library for those who like a bit
of immutability in their collections.
The link has lots more info, but the short of it is: the library provides
new types splitting the SDK collection interfaces in half:
+ List --> BuiltList (immutable) and ListBuilder (mutable)
+ Set --> BuiltSet (immutable) and SetBuilder (mutable)
+ Map --> BuiltMap (immutable) and MapBuilder (mutable)
Code example:
var list = new BuiltList<int>([1, 2, 3]);
var updatedList = (list.toBuilder()..add(4)..add(5)).build();
var updatedMoreList = (updatedList.toBuilder()..where((x) => (x >
2))).build();
And a few nice points:
MyClass(this.builtList); // no need to copy defensively, it's immutable!
if (builtList1 == builtList2) { ... // deep comparison
var lists = new Set<BuiltList<int>>(); // deep hashCode, can be used in
sets/maps
new BuildList<int>([null]); // throws, nulls aren't allowed
Background:
I work at Google on a project that uses Dart, rather than the Dart team
itself. We've found this approach to collections to be very useful in
building immutable data types to represent UI state and for RPCs. We
decided to rewrite the custom collections we were using for open source
release in the hope that others would find them useful. So, enjoy :) ...
and please do provide feedback, to me directly or on the github issue
tracker: https://github.com/google/built-collection-dart
Regards
Morgan
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.