proposal-array-filtering: Alias problem
While I agree that the filter method is very confusing, a thing I would hate more is having aliases. Array.prototype.filter will most likely not be removed/deprecated when select will make its way into JavaScript. Which will mean we will have 2 1:1 methods. My 2 cents are that I support this proposal only if it will ensure that programmers wont have to choose between filter and select.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 21
- Comments: 18 (12 by maintainers)
To be fair tho, in the first case, that’s because the protocol requires all three of keys/values/entries; in the second two, that’s because the right/left variants were impossible to remove, and ended up effectively deprecated, in annex b.
I don’t think any of those three serves as precedent for this proposal.
In .NET’s LINQ
enumerable.Select(x => ...)means a projection (Array.map). People coming from C# would certainly be confused.I think this falls into a linter concern. Certainly seeing mixed use of
.filterand.selectisn’t ideal, but but giving people the option to choose.selectis worth it to both the writer and reader.Note that we have other aliases already in the language:
Set.prototype.keysis an alias ofSet.prototype.valuesString.prototype.trimLeftis an alias ofString.prototype.trimStartString.prototype.trimRightis an alias ofString.prototype.trimEnd(That’s not including the aliases from the
@@iteratorto some other method)Just popping in to register my dislike of an alias. I’m in favor of
reject(orfilterOut, or whatever the final name is) though 👍No, TC39 is considering “making filtering easier”, which means looking at the inverse function (
rejector whatever we name it) and others likepartition. The proposal reached Stage 1 with this as the direction.TC39 decided to reject (🥁) creating an alias, so we will not be getting a
select. Closing this as resolved.I really like this idea. So I’ve added it to one of my packages jsmodern for TypeScript users (
denousers should never miss this).I love the idea of a
rejectmethod onArray.prototype. Or it could be calledfilterOutor any other name that makes sense and fits within our existing ecosystem.The
selectname makes sense if one comes from a Ruby background, but does not if one comes from a LISP, .NET, Java, or SQL background.One potential issue I see with
rejectis thatArray.prototype.rejectis very different fromPromise.rejectdespite sharing the same name. It could lead to some confusion.As an aside, if we add
reject, it might be appropriate to addpartitionthat could act similarly to https://lodash.com/docs/4.17.15#partition — this also might be out-of-scope.And when reading, when there’s no autocomplete list? Or people who just use and editor and not and IDE (like me)?