One thing that helps in some of these cases, and not many people seem to 
know, is that you can match "several levels" at once, like so:

type Top
    = Some
    | Other (Maybe Int)

-- and then match with

case value of
    Other (Just n) ->
        doStuffwith n

    Other Nothing ->
        doWithoutNumber

    Some ->
        doSomething



On Wednesday, March 29, 2017 at 7:40:40 PM UTC+3, Matthieu Pizenberg wrote:
>
> Multiple times in my projects, I happen to need nested pattern matching.
> Below is a raw extract of code (in an update) showing this need.
>
> Study.ScribblesMsg scribblesMsg ->
>     case model.study.status of
>         Study.Progressing steps ->
>             case Pivot.getC steps of
>                 Study.ScribblesStep ( imageUrl, scribbles ) ->
>                     ( Scribbles.update scribblesMsg model scribbles
>                     , Cmd.none
>                     )
>
>                 _ ->
>                     ( model, Cmd.none )
>
>         _ ->
>             ( model, Cmd.none )
>
> Basically, this is a specific case of a generic following code:
>
> case f1 var1 of
>     DataType2 var2 ->
>         ...
>             case fn varn of
>                 finalVar ->
>                     doSomethingOf finalVar
>                 _ ->
>                     otherwise
>         ...
>      _ ->
>         otherwise
>
> Do you think there could exist a syntax enabling better handling of such a 
> case?
> Have you encountered one in another langage maybe?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to