Git Product home page Git Product logo

Comments (4)

Yonaba avatar Yonaba commented on July 22, 2024 1

Thanks @drauschenbach and @chessai for your suggestions. It was implemented via commit 7c01770.

from moses.

drauschenbach avatar drauschenbach commented on July 22, 2024
> _.print(moses.range(1, 0))
{}
> _.print(moses.range(1, 1))
{}
> _.print(moses.range(1, 2))
{1, 2}
> _.print(moses.range(1, 3))
{1, 2, 3}

from moses.

chessai avatar chessai commented on July 22, 2024

tl;dr: I agree, if a range is supposed to be isomorphic to the mathematical object of an interval, then range(1,1) is isomorphic to [1,1], which is just the degenerate interval.

This function works as according to the API docs:

"[_.range] --- Produces a flexible list of numbers. If one positive value is passed, will count from 0 to that value, with a default step of 1. If two values are passed, will count from the first one to the second one, with the same default step of 1. A third value passed will be considered a step value."

The problem is the inconsistency w.r.t. clusivity of endpoints, exactly as your examples point out.

(1): _range(1,1) = {}
(2): _range(1,2) = {1,2}
(3): _range(1,3) = {1,2,3}

In (2) and (3), the endpoints are treated as inclusive, while in (1), they are not. This is because it counts from 1 to 1, with a default step of 1.

from moses.

drauschenbach avatar drauschenbach commented on July 22, 2024

I use the following patched range function in my Spark runtime lib Stuart.

My patch is necessary because porting Spark involves porting Scala's semantics for a range function, which happens to match the lodash/underscore semantics. And that is really my benchmark for why moses is currently the anomaly with its unusable treatment of (1,1) params.

from moses.

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.