Giter VIP home page Giter VIP logo

Comments (7)

ljharb avatar ljharb commented on August 22, 2024 1

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.

bterlson avatar bterlson commented on August 22, 2024

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.

domenic avatar domenic commented on August 22, 2024

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.

ljharb avatar ljharb commented on August 22, 2024

If match takes an iterable, how would you match both a string literal and an array in the same construct?

from proposal-pattern-matching.

domenic avatar domenic commented on August 22, 2024

By putting the string first before the iterable pattern.

from proposal-pattern-matching.

ljharb avatar ljharb commented on August 22, 2024
match (iterable) {
  'foo': 
  [...]: 
}

What if I want to pass ['f', 'o', 'o']? Wouldn't that match the first pattern?

from proposal-pattern-matching.

domenic avatar domenic commented on August 22, 2024

No, not per the proposal in the readme.

from proposal-pattern-matching.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.