Comments (4)
Thanks @drauschenbach and @chessai for your suggestions. It was implemented via commit 7c01770.
from moses.
> _.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.
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.
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)
- sortBy API doc claims it sorts in-place, but it does not HOT 1
- Feature request: findWhere(t, f) HOT 1
- Feature request: unzip HOT 4
- Feature request: unpack() HOT 2
- sample() fails when array contains middleclass classes HOT 7
- Many functions not chainable because of f(i,k) 1st arg HOT 4
- Use of underscore ("_") and "M" from Lua Style Guide
- Bug in Intersect, Questions about Difference and Union HOT 1
- Syntax and performance questions? HOT 6
- Links in documentation not working correctly
- M.compose() HOT 6
- uid() alias refers to non-existent uniqueid() HOT 1
- 2.x is compatible with 1.x ? HOT 1
- powerset does not generate a power set HOT 1
- Don't treat io or os modules as mandatory (redis compatibility) HOT 4
- Feature request: mapi() HOT 2
- How does Moses compare to Lua Fun? HOT 6
- Interview With Moses Author?
- Please make moses available for 5.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 moses.