tc39 / proposal-built-in-modules

BSD 2-Clause "Simplified" License
891 stars 25 forks source link

Add remaining underscore / lodash features #38

Open mikemaccana opened 5 years ago

mikemaccana commented 5 years ago

Some points:

TC39 should implement the features from lodash andd underscore that do not already have ES equivalents.

littledan commented 5 years ago

We're working on optional chaining, which I think should handle use cases of _.get() when the path string is fixed. Can we continue this discussion in that repository?

realtaraharris commented 5 years ago

Please consider providing something equivalent to underscore's omit. I find myself reaching for this all the time.

Timer commented 5 years ago

Omit can be emulated using object destructuring:

> let a = { foo: 5, bar: 6, baz: 7 }
undefined
> a
{ foo: 5, bar: 6, baz: 7 }
> let { bar, ...noBar } = a
undefined
> noBar
{ foo: 5, baz: 7 }
mikemaccana commented 5 years ago

@littledan optional chaining sounds great, and yes any specific _.get()-specific discussion should be handled there. 👍

This issue is to enumerate the features from these commonly used libraries that do not currently have an ESnext equivalent - it's more than just a single feature. So yes let's please leave this open and find out what else is missing!

StoneCypher commented 5 years ago

It's weird because I recommended this, and it was closed as off topic and I was called disruptive

The next day Dan asked for this in public and now it's a good idea

There's a whole lot down there

https://github.com/tc39/proposal-javascript-standard-library/issues/39

StoneCypher commented 5 years ago

We really should pick up our basic functional predicates. Much of what lodash and ramda actually are are that.

The best place to look would be in the standard library of a very old functional language, like lisp, or a very active modern one, like clojure, because this is their bread and butter

It would be better to look at ramda than lodash. Underscore got a lot of its critical basics wrong in important ways

StoneCypher commented 5 years ago

Most important would be having a language-level deep copy

There are a bunch of really complicated decisions involved in deep copy, like what to do about cycles, how to handle classes with valueOf, et cetera

You can't really have a library deep copy, because it'll end up making a bunch of those decisions and not talking about them. Changing them, with time, the way jquery and underscore's keep doing.

Some of those decisions actually need access to the underlying jsvm

Take any two library implementations of deep copy and put them up to a stochastic tester like jsverify.

I've tested almost 50 of them at this point. I haven't found two that are compatible yet, except the ones that copy and paste one another.

The language needs a fundamental deep copy, so that downstream users can make adjustments to the deep copy that's present when the choices made don't fit needs.

renatoagds commented 5 years ago

@Timer using destruct we'll generate unused variables (such as bar in your example). I suggest add a specific utility for omit, that will return exactly what you need, without creating unused stuffs.

kasperpeulen commented 5 years ago

@renatoagds You could also write it like this:

let a = { foo: 5, bar: 6, baz: 7 };
let { bar: _, ...noBar } = a;
kasperpeulen commented 5 years ago

Another option:

let a = { foo: 5, bar: 6, baz: 7 };
var noBar = Object.assign(
    ...Object.entries(a)
        .filter(([key, value]) => key !== 'foo')
        .map(([key, value]) => ({ [key]: value }))
);

If we would have something like a Object.from we could simplify that to:

let a = { foo: 5, bar: 6, baz: 7 };
var noBar = Object.from(Object.entries(a).filter(([key, value]) => key !== 'foo'));
lazarljubenovic commented 5 years ago

Regarding Object.from, there's Object.fromEntries which is close to stage 4.

renatoagds commented 5 years ago

@kasperpeulen I know that we can do in a lot of ways, but that's exactly what lodash does. The exactly topic here is put this boilerplate inside the stdr library.

mikemaccana commented 5 years ago

@jdalton you've got some pretty unique insight here - any thoughts?

jdalton commented 5 years ago

Thanks for the ping @mikemaccana! I've been following this thread at a distance.

I believe the goal of this proposal is to define a mechanism for providing a more extensive standard library in JavaScript and not really about the specific methods that compose the various standard modules. We have a proposal process that folks can follow and bring to the attention of TC39 delegates like myself.

At the top of my wish list of things to be added to the language would be nicer ways to deep clone and deep compare _(think Node's util.isDeepStrictEqual)_ values.