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.

Reply via email to