Open littledan opened 5 years ago
@viktor-ku wrote:
If you have general
range
it isn't clear what type it's gonna produce: array, maybe set, maybe weak set or any other current or future iterable? Why is it worse in your opinion thanArray.range()
orSet.range()
hence adding methods toArray
orSet
directly without having to do this in standard lib? The same goes withlen
ortake
ormap
.
Having a range() function as a generator means that values can be pulled from it and used lazily, rather than having to populate a whole collection first. For use cases that need the values in an Array or Set, it's trivial to do:
new Set(range(10)) // Returns a Set with ten values from 0 to 9
[...range(1, 6)] // Array with five values from 1 to 5
Trees support is definitely one thing we want!
Object.is?
It wouldn't be web compatible to "fix" Sets and Maps to differentiate positive and negative zero, but with the rekey proposal, you'd be able to make your own Map and Set instances that did this differentiation.
@littledan sorry I meant SameValueZero
It wouldn't be web compatible to "fix" Sets and Maps to differentiate positive and negative zero
@ljharb yes, but it's probably possible to add new fixed versions of Set and Map to stdlib
Also it would be web compatible to have old broken Set and Map available globally and new fixed Set and Map available via protected namespace
It would; but I think it would be very confusing to have two things named "Map" that behaved differently.
but I think it would be very confusing to have two things named "Map" that behaved differently.
Number.isNaN
vs isNaN
comes to mind.
Indeed, a good example to avoid repeating :-)
Indeed, Map
and Array.prototype.map
also come to mind too.
Here's a summary of the most popular proposals based on the 👍:
Good summary, those all seem like good ideas (though I'm skeptical of the last one).
though I'm skeptical of the last one
If partial application ever reaches stage 4, you will have to bow down to our new functional overlords.
Certainly a Result would work very well in Promise.allSettled, and in the proposed Set/Map find methods, and a number of other places.
I kinda wish Promises never happened in JS core. They're eager evaluated and miss valuable use cases (ex async vs waterfall vs parallel) that some of the more popular Promise libs (ex bluebird, async.js) provide out of the box.
I like the idea of Futures as a 'do over' to provide a more useful alternative to promises.
Hello, for anyone who wants a range
in JS, here is an independent proposal about range https://github.com/Jack-Works/proposal-Number.range
If you are adding a static method for numbers then Id expect the analogue on String
to generate range of characters:
/* String.range(range: String, charset = 'UTF-8': String): String */
String.range('∏-»', 'machintosh'); // ∏π∫ªºΩæø¿¡¬√ƒ≈∆«»
String.range('Ø-é', 'ISO-8859-1'); // ØÙÚÛÜÝÞßàáâãäåæçèé
If you are adding a static method for numbers then Id expect the analogue on
String
to generate range of characters:/* String.range(range: String, charset = 'UTF-8': String): String */ String.range('∏-»', 'machintosh'); // ∏π∫ªºΩæø¿¡¬√ƒ≈∆«» String.range('Ø-é', 'ISO-8859-1'); // ØÙÚÛÜÝÞßàáâãäåæçèé
The range for String is not in the goals of Number.range, you can build your own proposal, I'll focus on numbers and BigInts only 😉
I was using the generic you i.e. I wasn't talking to you :) What I meant is that a generic range module would have to support characters and numbers.
@Mouvedia This might be derailing the conversation, but what is the purpose/use case of a string range generator?
@obedm503 you will have to come up with the use cases yourself.
ruby: https://ruby-doc.org/core-2.2.0/Range.html PHP: http://php.net/manual/fr/function.range.php groovy: http://groovy-lang.org/operators.html#_range_operator swift: Range/ClosedRange nim: https://nim-lang.org/docs/system.html#..%2CT%2CU prototype: http://prototypejs.org/doc/latest/language/ObjectRange/ etc.
Trees support is definitely one thing we want!
a builtin sqlite3 (like python) would be far more practical and useful in web-applications than a low-level tree-library.
i don't know how it would be implemented, but some sort of full-text-search primitives would greatly benefit the industry.
@kaizhu256 a builtin sqlite3 (like python) would be far more practical and useful in web-applications than a low-level tree-library.
Local storage can be used for quickly/easily persisting smaller amounts of data. Also, keep in mind that this would be for JS as a whole; so probably needs to be useful in bith the browser and node.
i may be wrong but i think what industry really wants is a "standardized" sqlite3 in browser with full-text-search capabilities (ala websql, which never seems to have truly died [1]). indexeddb is just terrible in terms of practical usability/performance (joins need to be done in userland-javascript? really?).
adding a low-level tree-library so users can reinvent even crappier versions of indexeddb is pointless.
i also don't mind a sqlite3-library to be memory-only, so it can be encapsulated for security reasons. one can always [infrequently] persist it to indexeddb as a blob.
speaking of indexedb, its sorely in need of an appendFile feature. without it, popular browser-db's like nedb are impractical for persisting largish datasets (> 20mb) [2].
[1] current websql browser-support https://caniuse.com/#search=websql
[2] nedb emulates appendFile by re-saving its entire database as a blob to indexedb whenever a row insert/delete/update is performed. https://github.com/louischatriot/nedb/blob/v1.6.0/browser-version/browser-specific/lib/storage.js#L49
I'd recommend making feature requests for IndexedDB in their GitHub repository; you're not likely to reach the right folks here.
related: https://github.com/samchon/tstl
leftpad?
leftpad?
It exists.
SQL is everywhere, and I think some sort of supported SQL library built in on top of indexedDB without downloading a megabyte of asm.js generated code would be amazing.
We also need generic versions of the whole array and string -prototype functions. For extra functionality, see python for inspiration. For example: https://docs.python.org/3/library/textwrap.html A universal print function! That must be in. Math and date functions. Especially date functions for dealing with time-zones and all. Some way to work with complex numbers in the math library?
Just look here: https://docs.python.org/3/library/ Let's tackle all the relevant ones!
@lazarljubenovic I stand corrected! Thanks :)
there already exists asm.js-compiled sqlite3 at http://kripken.github.io/sql.js/GUI/. curious on feasibility of having something similar (or wasm-variant) incorporated as standard-library?
The stdlib should be similar in functionality to that of other languages. As such, I would suggest taking something like lodash or underscore and pairing it down to its most useful functions. For example, JS has never had a simple way to deep-extend an object - but the two aforementioned libraries do. They are essentially the same thing and probably the most ubiquitous libs for basic operations.
Suggestion: Start from Lodash or Underscore and pair back, then extend with any missing functionality but only those that affect the built-in objects.
@bfattori-TDA IMO, lodash/underscore are a step in the right direction in terms of providing functional transforms for data.
Unfortunately, if the pipeline-operator proposal passes, we'll likely see their functionality re-incarnated in a new library that fully leverages native pipes. Adding them in their current form would be premature.
The JavaScript standard library is very minimal. Is this how it should be? What should we add?
Note, the purpose of this repository is to develop the infrastructure for built-in modules, not the contents. However, I know many of you have ideas for the contents as well, so let's brainstorm those in this issue exclusively.