GithubHelp home page GithubHelp logo

slice(-10, -2) === slice(0, 8) about imlazy HOT 6 CLOSED

benji6 avatar benji6 commented on May 18, 2024
slice(-10, -2) === slice(0, 8)

from imlazy.

Comments (6)

benji6 avatar benji6 commented on May 18, 2024

Yeah I didn't really give any thought to negative arguments and haven't said anything about that in the docs. I see you handle it like this https://github.com/xgbuils/iterarray/blob/master/src/index.js#L39 I'm thinking if any of the arguments are negative I'll just handle it like native slice - possibly by just spreading into an array and dispatching to native slice because that's the easiest way to do it! :D I might submit a PR on this soon

from imlazy.

xgbuils avatar xgbuils commented on May 18, 2024

I like your approach following the native slice behaviour. But it's a bit eager for infinite iterables.

from imlazy.

xgbuils avatar xgbuils commented on May 18, 2024

And if you want to assume this eager behaviour, I suggest to put if (n >= m) return module.exports.empty() sentence first to avoid some cases that is no way necessary to resolve eagerly.

from imlazy.

benji6 avatar benji6 commented on May 18, 2024

That then breaks the behavior with negative indices: slice(0, -1, range(1,3)) should be (1 2) not (). That's why I put the if (n >= m) return module.exports.empty() second. To mimic native slice it has to be eager because the offset is done from the end of the iterable so I think this is fine

from imlazy.

xgbuils avatar xgbuils commented on May 18, 2024

It's true. When I said that, I was thinking on n < 0 && m < 0 case. In this case if (n >= m) return module.exports.empty() sentence is valid. I mean slice(-2, -5, iterable) always returns empty iterable regardless if iterable is infinite or not. But in cases that one parameter is negative and the other not, it seems that eager solution is the best solution.

from imlazy.

benji6 avatar benji6 commented on May 18, 2024

Ah yeah, very good point then! I'll add a test case, make the change then merge this

from imlazy.

Related Issues (19)

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.