gleam-lang / suggestions

📙 A place for ideas and feedback
26 stars 2 forks source link

Alternative patterns not at the top level #115

Open varnerac opened 3 years ago

varnerac commented 3 years ago

Rust and ReasonML allow you to combine patterns in switch/case statements. I think it's nice.

switch (items) {
  | [1, 2]
  | [3, 4] => "is 1,2 or 3,4"
  | [5, 6 | 7, ..._] => "starts with 5, then has 6 or 7"
  | _ => ""
};
lpil commented 3 years ago

We support this at the top level, but not nested yet.

case x {
  1 | 2 -> "one or two"
  _ -> "other"
}

It would be good to have this nested syntax too, though implementation seems like it could be tricky.

varnerac commented 3 years ago

Ok, I am embarrassed I was too lazy to scroll down the page. Gonna close.

lpil commented 3 years ago

Oh no let's keep this open! The example you've given won't compile! It would be great if we could have that functionality as well.

varnerac commented 3 years ago

Oh, okay

lpil commented 3 years ago

Thank you! This will be a big improvement :)

On Thu, 7 Jan 2021, 17:48 Andrew Varner, notifications@github.com wrote:

Oh, okay

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/gleam-lang/suggestions/issues/115#issuecomment-756272939, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOZVBQ4XZQX37M2F4FEHR3SYXXVVANCNFSM4VZDEBYA .