Comments (7)
Thanks, that clears it up a bit - so you're suggesting that the [ ]
syntax pivot on iterability and not just arraylike-ness - and since strings are both arraylike and iterable, they don't impact this issue's topic at all.
from proposal-pattern-matching.
I will include some text around the difficulty of doing this. I think it's possible but it's potentially hard to implement and potentially difficult to think through side effects. Consider:
match (iterable) {
[ x, y, z ]: // iterable .next called 4 times (last to confirm done: true)
[ x, y ]: // either iterable rewinds, or more likely, previous values for this iterator are cached...
}
from proposal-pattern-matching.
Hmm, so it wouldn't work obviously nicely on one-shot iterators, I see. I was hoping it would be analogous to
const [x, y, z] = iterable; // does this throw or not? if so, try next line:
const [x2, y2] = iterable;
but yeah, it's not that simple.
from proposal-pattern-matching.
If match takes an iterable, how would you match both a string literal and an array in the same construct?
from proposal-pattern-matching.
By putting the string first before the iterable pattern.
from proposal-pattern-matching.
match (iterable) {
'foo': …
[...]: …
}
What if I want to pass ['f', 'o', 'o']
? Wouldn't that match the first pattern?
from proposal-pattern-matching.
No, not per the proposal in the readme.
from proposal-pattern-matching.
Related Issues (20)
- [spam]
- Design feedback from JSCIG HOT 9
- Rest spec work HOT 4
- Open question: `Promise[Symbol.matcher]` HOT 7
- Error subclasses: how are they checked? HOT 26
- Confirm missing constructor matchers HOT 4
- RegExp pattern against a non-string matchable: stringify or fail? HOT 8
- More ergonomic custom matchers HOT 9
- Add a more relevant react example using react-query HOT 4
- InterpolationPatternMatches HOT 4
- Grammar ambiguities HOT 5
- We should reframe the approach here HOT 64
- Even simpler custom matchers HOT 11
- Move irrefutable/binding matchers to a different syntax HOT 4
- Stage 2 and `when` HOT 1
- Alternative syntax design: `case => ...` vs `when : ...` HOT 11
- Pattern-matching `#record{}` & `#tuple[]` HOT 3
- Spec: Use Map instead of WeakMap HOT 4
- Inappropriate example HOT 2
- Allow providing error message in Matcher protocol HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-pattern-matching.