Skip to content

Commit bc3d5d9

Browse files
initial commit
0 parents  commit bc3d5d9

11 files changed

Lines changed: 2151 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build spec
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 22
18+
- name: install dependencies
19+
run: npm ci
20+
- name: build spec
21+
run: npm run spec

.github/workflows/deploy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy gh-pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 20
19+
- run: >
20+
npm ci &&
21+
npm run build &&
22+
npm run spec
23+
- uses: JamesIves/github-pages-deploy-action@v4.5.0
24+
with:
25+
branch: gh-pages
26+
folder: dist
27+
clean: true

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Run tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: 22
14+
- name: install dependencies
15+
run: npm ci
16+
- name: build
17+
run: npm run build
18+
- name: test
19+
run: npm test

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tsconfig.tsbuildinfo
2+
lib
3+
node_modules
4+
biblio.json
5+
dist

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Iterator Includes
2+
===
3+
4+
A TC39 proposal to allow the developer to ask whether an iterator yields a given value. Analogue to `Array.prototype.includes`.
5+
6+
**Stage: 0**
7+
**Specification:** https://tc39.es/proposal-iterator-includes/
8+
9+
## presentations to committee
10+
11+
- [March 2026](https://docs.google.com/presentation/d/1a-1RQayP-tcJd2VAhFGoiL_dRT8gD8_qrp__qSgC1A4)
12+
13+
## motivation
14+
15+
This proposal has the same motivation as the original
16+
[`Array.prototype.includes`
17+
proposal](https://github.com/tc39/proposal-Array.prototype.includes). Just as
18+
you do with Arrays, at times you need to ask whether an iterator would yield a
19+
given value. And as with Arrays, you can use `some` with a custom comparator,
20+
but that's not ideal because it doesn't as directly express your intent, and
21+
each time you need to do that, you have the option of one of many comparison
22+
operations, when that choice often doesn't matter. There should be a simple,
23+
terse, standard way to look for something in the values yielded by an iterator.
24+
25+
## design questions
26+
27+
### comparison operation
28+
29+
There are at least 4 built-in comparison operations that somebody could want to
30+
use for `includes`: strict equality (`===`), loose equality (`==`), SameValue
31+
(`Object.is`), and SameValueZero (`Array.prototype.includes`). In a vacuum, we
32+
could debate the merits of SameValue vs SameValueZero and which is best for
33+
known popular use cases, but I don't think there's any argument that would be
34+
stronger than choosing SameValueZero to match `Array.prototype.includes`.
35+
36+
### second parameter (fromIndex)
37+
38+
`Array.prototype.includes` has a second parameter that starts the search from
39+
the given index instead of the beginning of the Array. This makes sense for the
40+
Array API because the alternative (slicing first) would first allocate another
41+
Array and then perform a copy from that index. But Iterators have `drop` which
42+
is a constant time/space operation, so there's no need to include this
43+
parameter. That being said, it *could* be included to mirror the Array API, but
44+
I don't think it's worth it. Additionally, if it was included, it would have to
45+
reject negative values, which would be an unnecessarily surprising difference.
46+
47+
## chosen solution
48+
49+
A new `Iterator.prototype` method named `includes`.
50+
51+
```js
52+
function* gen() { yield 1; yield 3; };
53+
gen().includes(1); // true
54+
gen().includes(2); // false
55+
gen().includes(3); // true
56+
57+
gen().drop(1).includes(1); // false
58+
gen().drop(1).includes(3); // true
59+
gen().drop(2).includes(3); // false
60+
```

0 commit comments

Comments
 (0)