Skip to content

Provide Range function/class #42652

Open
Open
@MarcelGarus

Description

@MarcelGarus

In Dart code, I see code with the following structure very often:

for (var i = 0; i < 10; i++) {
  print('Hello world');
}

This is a very imperative way of programming (first, setting i to 0, then checking if i < 10 and after each iteration increasing i by one).
Most people try to code in a higher-level declarative way and I thought it's weird that the Dart core SDK doesn't have something like a Range that could be created with a to extension method on int so that you could simply do

for (final i in 0.to(10)) {
  print('Hello world');
}

Sure, there are third-party packages that offer this functionality, but this is such a fundamental, basic functionality that I believe it's common enough to be in the standard library. I'm looking forward seeing this being integrated into the platform.

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.library-coretype-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