question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

should pure-value cases narrow?

See original GitHub issue

Currently, a case with only values, such as case ("foo"|"bar") doesn’t narrow the type of the switched variable. After #4402 that’s inconsistent and special-casey. Also it would be useful to narrow the type when you have multiple values listed in a single case.

I think we should change this. However, it would be a source code breaking change, since in 1.x we allowed you to have a variable switch expression if all the cases were value cases. We would have to close that loophole.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Apr 28, 2018

One could decide to narrow only if it is not variable.

Alright, @ePaul, so I figured out a way to implement this. It’s kinda nasty but in a way, but not actually fragile. It’s on the 7248 branch.

Still, I will probably add a deprecation warning to the case of switching a variable, since this behavior is pretty inconsistent with how is and exists conditions treat variables.

0reactions
gavinkingcommented, Apr 28, 2018

Spec updated, closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RPV: Pure Value Is Outpacing The S&P 500 This Year ...
This article will compare RPV's strategy and fundamentals with a more popular broad-based value ETF and make the case that as long as ......
Read more >
S&P U.S. Style Indices Methodology
The second need is for narrow, style-pure indices. The Style index series divides the ... Number of Stocks in S&P SmallCap 600 Pure...
Read more >
How to properly force evaluation of pure value in IO monad?
Daniel Wagner's answer is fine for this use-case, but sometimes it's also beneficial to just evaluate the spine of a list and leave...
Read more >
Russell Pure Style Indexes
Russell 1000® Pure Value Index. Small Cap. Russell 2000® Pure Growth Index. Russell 2000® Pure Value Index. Mid Cap. Russell Midcap Pure Growth...
Read more >
Super Thinnest iPhone XS Max Slim Cases without Adding ...
If you are not dwelling in a location that is surrounded by hazardous materials all around, then a thin case is something you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found