Skip to content

Collection transformations should return "views" not "snapshots" #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DartBot opened this issue Jan 23, 2012 · 2 comments
Closed

Collection transformations should return "views" not "snapshots" #1305

DartBot opened this issue Jan 23, 2012 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 23, 2012

This issue was originally filed by @seaneagan


The following methods transform one Collection into another:

Map#getKeys
Map#getValues
Collection#filter
Collection#map (see issue #945)

At least some of these currently return an eager "snapshots" of the transformation.

They should instead return lazy "views" backed by the original Collection. Here's why:

* Avoids copying internal values (which is O(n))

* Can chain together multiple transformations without creating intermediate throw away Collections.

* Avoid having to call the method every single time updated values from the original Collection are needed (the majority use case).

* Copy constructors are already a much more orthogonal way to snapshot Collections, on the rare occasion that that is needed. For example:

// see issue #1248
new Set.from(map.keys)
new List.from(map.values)

// see issue #1304
new Collection.from(collection.filter(callback))
new Collection.from(collection.map(callback))

@dgrove
Copy link
Contributor

dgrove commented Jan 25, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Library, Triaged labels.

@lrhn
Copy link
Member

lrhn commented Aug 21, 2013

They return views now.


Added Fixed label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Aug 21, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants