Skip to content

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

Closed
@DartBot

Description

@DartBot

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions