-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems
Description
TL;DR: Dart lacks some way to do pattern matching on Iterable
directly
When we use Iterables without transforming said Iterable into a List/Set/... (such as to avoid allocating a large collection), we end-up lacking a mean to use pattern matching.
Could we maybe have some Iterable-specific way to express a pattern match?
We could imagine #(a, b, c)
as syntax for such pattern:
final list = [1, 2, 3];
final iterable = list.where((e) => e.isOdd);
switch (iterable) {
case #(1, 3):
}
Or course, the token used could be anything else. Like #[]
, or not even use #
.
Relying on ()
makes sense to me because Iterable.toString()
uses ()
. But of course, this (1, 2)
is taken by Record patterns.
Bonus:
- Support
#(1, 2, ...)
- Support
#(1, 2, ...final other)
whereother
is an Iterable
Metadata
Metadata
Assignees
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems