Skip to content
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

No List constructor takes Iterator<E> #17694

Closed
paulevans-sonar opened this issue Mar 21, 2014 · 5 comments
Closed

No List constructor takes Iterator<E> #17694

paulevans-sonar opened this issue Mar 21, 2014 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant core-n library-core type-enhancement A request for a change that isn't a bug

Comments

@paulevans-sonar
Copy link

You cannot create a List from an Iterator<E> - construction requires an Iterable<E> which wraps an iterator getter that returns an Iterator<E>
 
It would be convenient if the programmer already has an iterator to use that rather than require the Iterator be wrapped in an Iteratable. For example if a function only requires an Iterator<E> without caring about what collection it came from (map, set, random generator, whatever) and internally wanted to represent that as a list while processing it.

Though to be fair it looks like List.from(...) just goes over the collection at least once, perhaps going over and allocating a second list if fixed length is requested. Ideally this cost would be hinted at in the documentation.

// Copied from list.dart
  /**
   * Creates a list and initializes it using the contents of [other].
   *
   * The [Iterator] of [other] provides the order of the objects.
   *
   * This constructor returns a growable list if [growable] is true;
   * otherwise, it returns a fixed-length list.
   */
  factory List.from(Iterable other, { bool growable: true }) {
    List<E> list = new List<E>();
    for (E e in other) {
      list.add(e);
    }
    if (growable) return list;
    return makeListFixedLength(list);
  }

@kevmoo
Copy link
Member

kevmoo commented Mar 21, 2014

Added Library-Core, Triaged labels.

@lrhn
Copy link
Member

lrhn commented Mar 22, 2014

Removed Type-Defect label.
Added Type-Enhancement label.

@lrhn
Copy link
Member

lrhn commented Mar 22, 2014

Added Area-Library label.

@floitschG
Copy link
Contributor

Changed the title to: "No List constructor takes Iterator".

@paulevans-sonar paulevans-sonar added Type-Enhancement library-core area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Mar 22, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn added the core-m label Aug 11, 2017
@floitschG floitschG added core-n and removed core-m labels Aug 24, 2017
@matanlurey
Copy link
Contributor

There is List.of now.

@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
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. closed-obsolete Closed as the reported issue is no longer relevant core-n library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants