Gleam: Support literal values in guards

Created on 18 Apr 2020  Â·  20Comments  Â·  Source: gleam-lang/gleam

case x {
  _ if x == 1 -> "here we are using an Int literal"
}
  • [x] Int
  • [x] Float
  • [x] Tuple
  • [x] List
  • [x] Records
  • [x] String

If you pick up this ticket please no more than one implementation per PR please so that it is easier to review. Thanks!

help wanted

Most helpful comment

That is a good reason. I'll add them in a new PR.

All 20 comments

Working on this!

Thank you @kyle-sammons ! Let me know if you would like any pointer on implementation

Just a suggestion but what about.

case x {
  1 -> "this is an int literal pattern"
  _ -> ""
}

That would be a better way to express that, it's more an example to explain the syntax.

A slightly more realistic example might be something like this:

case x {
  Ok(i) if i > 3 -> True
  _ -> False
}

Could you add some detail about what this looks like for compound types?

Does this help?

case x {
  Ok(i) if i == [] || i == [1] -> True
  _ -> False
}

Hi @kyle-sammons are you still working on this? Thanks

I'm interested in taking a stab at the tuple implementation if no one is currently looking at that :)

@lpil I am, I am. Hopefully finishing up the tuple implementation today. @QuinnWilton you can totally take either the List or Record one if you want to help out!

Thanks @kyle-sammons! I'll likely start work on one of those tasks in the next few days if you haven't gotten to them by then :)

Just an update -- I have not started work on the list implementation. I've been spending my time thinking about another issue (#34), so list and record support are both unclaimed at the moment.

No-one's working on those last two right? I'll do lists now and unless there's any other takers I'm happy to do records too.

@tomwhatmore Hey-o, I've actually been working on the list implementation. If you want to knock out the record one, though, go for it! :)

@kyle-sammons Sure, no problem, I'll do records instead.

Is there a reason why string literals aren't on this list?

I forgot! Oops!

On Fri, 22 May 2020 at 11:14, Tom Whatmore notifications@github.com wrote:

Is there a reason why string literals aren't on this list?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gleam-lang/gleam/issues/465#issuecomment-632614141,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABOZVBWZUFIK7Q4QGBUG2JTRSZF7ZANCNFSM4MLP7SUQ
.

That is a good reason. I'll add them in a new PR.

@kyle-sammons Are you working on this? :)

@lpil So sorry, but I don't think I'll be able to finish off the list implementation. Life has gotten increasingly complex with the recent pandemic and taken away most of my free time 😞

No problem at all, I totally understand! Thank you for the work so far 💜

Was this page helpful?
0 / 5 - 0 ratings