The previous proposal on this topic:
https://groups.google.com/g/elixir-lang-core/c/LEUD2alHPiE.
This is something I've been wanting for a while personally to avoid the
silently filtering out issue, but I think it's worth mentioning as a
counterpoint as well:
Hopefully the argument about being able to catch typos etc will be less and
less of an issue as the type system makes progress, and can point out that
the "clause will never match". It wouldn't catch a type that could match
though, e.g. a {x, y} | nil union, so there's still an argument to be made
for strict filtering.
Also, not a very satisfying solution, but strict filtering can be achieved
today using this workaround:
for tuple <- tuples, {x, y} = tuple, do: ...
Le mar. 20 janv. 2026 à 05:33, Bruce Tate <[email protected]> a écrit :
> Fair point.
>
> On Mon, Jan 19, 2026 at 9:25 AM Amos King <[email protected]> wrote:
>
>> An option would change the entire comprehension and not a single match
>> which I think would be less than ideal.
>>
>> I think of ‘for’ when I want to filter and combine permutations. If I
>> want to match I generally use Enum.map and when the fun doesn’t match you
>> get an error.
>>
>> I personally like the strong distinction between when I want to use a
>> ‘go’ vs Enum functions. A slightly different arrow can be easy to overlook
>> when reading code or even when writing it.
>>
>>
>> Amos
>>
>> On Jan 19, 2026, at 07:40, Bruce Tate <[email protected]> wrote:
>>
>>
>> Maybe an option like *strict: true*, or mode: *strict | match*, or *mode:
>> match | **destrcuture* would work?
>>
>> -bt
>>
>> On Mon, Jan 19, 2026 at 8:30 AM Hannes Steffenhagen <
>> [email protected]> wrote:
>>
>>> Right now, when you write a list comprehension with a pattern match, if
>>> the match fails the result is "discarded", so effectively the pattern match
>>> acts as a filter. This is convenient in some cases, but doesn't leave an
>>> obvious option to use when you wanted to use the pattern match only for
>>> destructuring, not filtering. E.g: in
>>>
>>> for {x,y} <- pairs do...
>>>
>>> We expect 'pairs' to to only contain pairs. It'd be unexpected for there
>>> to be anything else in there, but if by mistake (e.g. during refactoring)
>>> something else manages to sneak in there we may silently discard it which
>>> is a source of easy to miss bugs. This happened to us in the 'real world'
>>> during a refactor where we started to return a list of %{id:, name:}
>>> structs instead of a list of pairs from a function. Of course cases like
>>> that can often be caught with test coverage, but it'd be nice to have some
>>> way to explicitly say that we expect the pattern match to succeed, and
>>> raise if not, so cases that slip through the cracks don't lead to hard to
>>> trace bugs.
>>>
>>> In Erlang, with https://www.erlang.org/eeps/eep-0070 we have strict
>>> comprehensions now with the syntax <:-.. I don't know if that syntax would
>>> be appropriate for Elixir, but if not I am sure we could think of some
>>> other syntax for it.
>>>
>>> Apologies if this had already been discussed, I couldn't find a
>>> discussion on it other than a comment by Jose on this github issue that it
>>> would have to be something to be discussed separately:
>>> https://github.com/elixir-lang/elixir/issues/14148#issuecomment-3126519887
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/elixir-lang-core/34bd1126-03aa-4859-a23b-5c69bf351d3dn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/elixir-lang-core/34bd1126-03aa-4859-a23b-5c69bf351d3dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>>
>> Regards,
>> Bruce Tate
>> CEO
>>
>>
>> <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97>
>>
>> Groxio, LLC.
>> 512.799.9366
>> [email protected]
>> grox.io
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-79V6YwDNzKjgctvY5xwoFbF7bbs7Md1TJO7nQK6Ux0ww%40mail.gmail.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-79V6YwDNzKjgctvY5xwoFbF7bbs7Md1TJO7nQK6Ux0ww%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/elixir-lang-core/0CADB481-F911-4F5B-8761-C07577704840%40binarynoggin.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/0CADB481-F911-4F5B-8761-C07577704840%40binarynoggin.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
>
> Regards,
> Bruce Tate
> CEO
>
>
> <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97>
>
> Groxio, LLC.
> 512.799.9366
> [email protected]
> grox.io
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-7EVKX9r1zaEMW0yKkYz%2BCbTh%2BtVrWS2TFYc6TAD%3DssDA%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-7EVKX9r1zaEMW0yKkYz%2BCbTh%2BtVrWS2TFYc6TAD%3DssDA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/elixir-lang-core/CANnyohbiunXcDugL%2B7VP0mwDpE%3D1o6ZL3kwrVzfO8w-fRzrHqw%40mail.gmail.com.