Skip to content

Commit 60e9a1e

Browse files
authored
Pivot to filterOut, add spec text (#8)
* Pivot to filterOut, add spec text * Link to Array.prototype spec section
1 parent bce7a7e commit 60e9a1e

File tree

8 files changed

+2048
-51
lines changed

8 files changed

+2048
-51
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
index.html -diff merge=ours
2+
spec.js -diff merge=ours
3+
spec.css -diff merge=ours

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# nyc test coverage
18+
.nyc_output
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# node-waf configuration
24+
.lock-wscript
25+
26+
# Compiled binary addons (http://nodejs.org/api/addons.html)
27+
build/Release
28+
29+
# Dependency directories
30+
node_modules
31+
jspm_packages
32+
33+
# Optional npm cache directory
34+
.npm
35+
36+
# Optional REPL history
37+
.node_repl_history
38+
39+
# Only apps should have lockfiles
40+
yarn.lock
41+
package-lock.json
42+
npm-shrinkwrap.json

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 ECMA TC39 and contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
proposal-array-select-reject
2-
============================
1+
# proposal-array-filtering
32

4-
A Stage 1 proposal to add `Array.prototype.select` and
5-
`Array.prototype.reject`.
3+
A proposal to add `Array.prototype.filterOut`.
64

75
```js
86
const array = [1, 2, 3, 4, 5];
97

10-
// Select is just an alias for Array.p.filter
11-
array.select(i => (i < 3)); // => [1, 2];
8+
// filter keeps the items that return true.
9+
array.filter(i => (i < 3)); // => [1, 2];
1210

13-
// Reject does the opposite of select.
14-
array.reject(i => (i < 3)); // => [3, 4, 5];
11+
// filterOut removes the items that return true.
12+
array.filterOut(i => (i < 3)); // => [3, 4, 5];
1513
```
1614

17-
Motivation
18-
----------
15+
## Champions
1916

20-
`Array.prototype.filter` is confusing. I constantly have to ask myself
21-
"am I filtering in, or filtering out the current item?".
17+
- Justin Ridgewell ([@jridgewell](https://github.com/jridgewell/))
18+
19+
## Status
20+
21+
Current [Stage](https://tc39.es/process-document/): 1
22+
23+
## Motivation
24+
25+
`Array.p.filter` is confusing. I constantly have to ask myself "am I
26+
keeping, or filtering out the current item?".
2227

2328
<dl>
24-
<dt>"Filtering in"</dt>
29+
<dt>"Keeping"</dt>
2530
<dd>
2631

2732
Implies that returning `true` would keep the current item.
@@ -36,55 +41,32 @@ Motivation
3641
</dd>
3742
</dl>
3843

39-
`Array.p.filter` acts as "filtering in". But when I think of the word
44+
`Array.p.filter` acts as "keeping". But when I think of the word
4045
"filter", I think of "filtering out". So every time that I attempt to
4146
write an array filter, I end up writing the opposite of what I intended.
4247

43-
`Array.p.select` fixes this confusion. You are _selecting_ the current
44-
item. Similarly, `Array.p.reject` means you are _rejecting_ the current
45-
item.
46-
47-
48-
Semantics
49-
---------
50-
51-
### `Array.prototype.select(callbackfn[, thisArg ])`
52-
53-
The initial value of the `select` property is the same function object
54-
as the initial value of the `Array.prototype.filter` property.
55-
56-
### `Array.prototype.reject(callbackfn[, thisArg ])`
48+
`Array.p.filterOut` attempts to fix this confusion. By providing a
49+
clearly named filtering function that matches my intuition, I'm able
50+
what will happen when calling `filterOut`. And because it exists, I'm
51+
able to assume that `filter` does something different, so it must be
52+
"keep" version.
5753

58-
When the `reject` method is called with one or two arguments, the
59-
following steps are taken:
54+
## Ongoing Discussions
6055

61-
1. Let `O` be `? ToObject(this value)`.
62-
1. Let `len` be `? LengthOfArrayLike(O)`.
63-
1. If `IsCallable(callbackfn)` is `false`, throw a `TypeError` exception.
64-
1. If `thisArg` is present, let `T` be `thisArg`; else let `T` be `undefined`.
65-
1. Let `A` be `? ArraySpeciesCreate(O, 0)`.
66-
1. Let `k` be 0.
67-
1. Let `to` be 0.
68-
1. Repeat, while `k` &lt; `len`
69-
1. Let `Pk` be `! ToString(k)`.
70-
1. Let `kPresent` be `? HasProperty(O, Pk)`.
71-
1. If `kPresent` is `true`, then
72-
1. Let `kValue` be `? Get(O, Pk)`.
73-
1. Let `rejected` be `! ToBoolean(? Call(callbackfn, T, « kValue, k, O »))`.
74-
1. If `rejected` is `false`, then
75-
1. Perform `? CreateDataPropertyOrThrow(A, ! ToString(to), kValue)`.
76-
1. Set `to` to `to + 1`.
77-
1. Set `k` to `k + 1`.
78-
1. Return `A`.
56+
- [Supporting Data from HTTP Archive and GitHub Archive](https://github.com/jridgewell/proposal-array-filtering/issues/4)
57+
- [What should `filterOut` be called?](https://github.com/jridgewell/proposal-array-filtering/issues/6)
58+
- [Should `partition` be included?](https://github.com/jridgewell/proposal-array-filtering/issues/2)
7959

80-
Related
81-
-------
60+
## Related
8261

8362
- Ruby
8463
- [`Array#select`](https://ruby-doc.org/core-2.4.1/Array.html#method-i-select)
8564
- [`Array#reject`](https://ruby-doc.org/core-2.4.1/Array.html#method-i-reject)
65+
- [`Array#partition`](https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-partition)
8666
- Underscore
8767
- [`_.select`](https://underscorejs.org/#filter) (aliased to _.filter)
8868
- [`_.reject`](https://underscorejs.org/#reject)
69+
- [`_.partition`](https://underscorejs.org/#partition)
8970
- Lodash
90-
- [`_.reject`](https://lodash.com/docs/4.17.15#reject) ([700,000 downloads/week](https://www.npmjs.com/package/lodash.reject))
71+
- [`_.reject`](https://lodash.com/docs/4.17.15#reject) ([700k downloads/week](https://www.npmjs.com/package/lodash.reject))
72+
- [`_.partition`](https://lodash.com/docs/4.17.15#partition) ([18k downloads/week](https://www.npmjs.com/package/lodash.partition))

0 commit comments

Comments
 (0)