csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

Revamp proposal for list patterns on enumerables

Open jnm2 opened this issue 10 months ago • 4 comments

Someone with edit rights, please edit the proposal link in https://github.com/dotnet/csharplang/issues/9005 to https://github.com/dotnet/csharplang/blob/main/proposals/list-patterns-on-enumerables-2.md and edit the summary to:

Extends list patterns to be able to be used with enumerables that are not countable or indexable. `items.Where(...) is [var singleItem]`, or `is []`, or `is [p1, .., p2]`.

The pattern will be evaluated without multiple enumeration. The slice pattern `..` is supported, but only without a subpattern.

cc: @jcouv

jnm2 avatar Feb 22 '25 03:02 jnm2

@alrz If you're available, your feedback is welcome (I heard you had an impl at one point)

jnm2 avatar Feb 22 '25 05:02 jnm2

Can I ask in what ways this is indented to differ from the original? The prototype lives at https://github.com/dotnet/roslyn/pull/66553 based on the initial design (except for the buffer type contract explained in the description).

I've recorded open questions as PROTOTYPE comments there but I don't know how it maps to this updated version now.

alrz avatar Mar 01 '25 11:03 alrz

@alrz It differs in two ways. 1) It recommends disallowing subpatterns on the slice pattern, even if the enumerable is sliceable. 2) It uses the enumerator directly like the foreach statement does, rather than a helper type.

jnm2 avatar Mar 01 '25 18:03 jnm2

@alrz It differs in two ways. 1) It recommends disallowing subpatterns on the slice pattern, even if the enumerable is sliceable. 2) It uses the enumerator directly like the foreach statement does, rather than a helper type.

1 feels like it should just be added as an open question. 2 seems like a negative change, we moved to a helper type because the ldm had expressed some passing concern on codegen size. Neither of these feels like it should be a distinct proposal document; if anything, let's keep history intact by proposing updates to the existing document.

333fred avatar Mar 02 '25 14:03 333fred

Thanks for the feedback all! I will work on updating the original proposal instead of replacing it.

jnm2 avatar Sep 08 '25 23:09 jnm2