Skip to content

APIs that take List<X> should take Iterable<X> #247

Closed

Description

@FlutterIssues

Issue by ianloic
Monday Nov 02, 2015 at 22:34 GMT
Originally opened as https://github.com/flutter/engine/issues/1903


I'm often finding myself using List.map to turn a list of data objects into a list of widgets as children or menu items. Every time so far I've forgotten to .toList(). Is there a reason that the APIs that need a list of things don't just take an Iterable?

Activity

  1. FlutterIssues commented on Nov 9, 2015

    @FlutterIssues
    Author

    Comment by abarth
    Monday Nov 02, 2015 at 23:56 GMT


    /cc @Hixie

    We tried using Iterable at one point, but I don't remember when we ended up going back to List. Ian do you remember?

  2. FlutterIssues commented on Nov 9, 2015

    @FlutterIssues
    Author

    Comment by Hixie
    Tuesday Nov 03, 2015 at 00:09 GMT


    I forget the details, but it was in fn2, so it might no longer matter. We can try again.

  3. FlutterIssues commented on Nov 9, 2015

    @FlutterIssues
    Author

    Comment by sethladd
    Tuesday Nov 03, 2015 at 01:54 GMT


    Bonus: using Iterable means you can use yield :)

  4. self-assigned this
    on Dec 12, 2015
  5. added this to the milestone on Dec 12, 2015
  6. Hixie commented on Dec 12, 2015

    @Hixie
    Contributor

    Well, one reason is that we need to have a list we can iterate over. If all we were getting was an Iterable, then every time one was passed in, we'd have to call toList() on it, and that would basically double the number of copies of all the widget lists.

  7. Hixie commented on Dec 12, 2015

    @Hixie
    Contributor

    I don't really see a way to do this unless there's a way to get from a <Widget>[] literal to a List<Widget> via an Iterable<Widget> argument without paying the cost of a copy.

  8. removed their assignment
    on Dec 12, 2015
  9. abarth commented on Jan 11, 2016

    @abarth
    Contributor

    We do this for ScrollableList now. We actually can pull the iterator lazily in many cases too.

  10. abarth commented on Oct 16, 2016

    @abarth
    Contributor

    We've decided not to do this in general. There are some specific places that accept Iterable because they can work lazily. In the cases, however, we'd need to pull everything from the iterable anyhow and it's more efficient if we do that as early in the processing as possible (e.g., just after the iterable is created with something like map).

  11. github-actions commented on Aug 17, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions