Stream: beginners

Topic: destructuring lists when pattern matching


view this post on Zulip Nick Gravgaard (Oct 16 2022 at 07:32):

I'm trying to write something similar to this Elm code:

case myList of
    [] ->
        ...

    [ theOnlyItem ] ->
        ...

    items ->
        ...

Is it possible to destructure lists like this?

view this post on Zulip Brendan Hansknecht (Oct 16 2022 at 07:34):

Not currently. There has been discussion a few times around this

view this post on Zulip Brendan Hansknecht (Oct 16 2022 at 07:34):

I think it is likely to be added eventually, but not definite.

view this post on Zulip Nick Gravgaard (Oct 16 2022 at 07:37):

Ah shame. I really hope we end up with something like this. Thanks for the quick reply

view this post on Zulip Anton (Oct 16 2022 at 07:43):

I think we may already have an issue for this but I couldn't find it now.

view this post on Zulip Chris Duncan (Oct 16 2022 at 08:06):

Here's the issue you were looking for:
https://github.com/roc-lang/roc/issues/4171

view this post on Zulip Anton (Oct 16 2022 at 08:11):

Thanks @Chris Duncan :)


Last updated: Jul 05 2025 at 12:14 UTC