-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 progress: Import existing sources and tests from js-itertools.
- Loading branch information
1 parent
a7ca875
commit 2f13e63
Showing
9 changed files
with
10,106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Consumes a given number of iterations of the input iterator. | ||
* | ||
* @param {Iterator} iterator - The input iterator. | ||
* @param {Number} n - The number of iterations to consume. | ||
* | ||
*/ | ||
export default function consume(iterator, n) { | ||
// eslint-disable-next-line no-empty | ||
while (n-- > 0 && !iterator.next().done) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Exhausts the input iterator. | ||
* | ||
* @example | ||
* let it = range( 1000 ) ; | ||
* exhaust( it ) ; | ||
* list( it ) ; // returns [] | ||
* | ||
* @param {Iterator} iterator - The input iterator. | ||
* | ||
*/ | ||
export default function exhaust(iterator) { | ||
// eslint-disable-next-line no-empty,no-unused-vars,prettier/prettier | ||
for (const item of iterator) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const answer = 42; | ||
export default answer; | ||
export {default as consume} from './consume.js'; | ||
export {default as exhaust} from './exhaust.js'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import test from 'ava'; | ||
|
||
import {range} from '@iterable-iterator/range'; | ||
import {list} from '@iterable-iterator/list'; | ||
import {consume} from '../../src/index.js'; | ||
|
||
test('consume', (t) => { | ||
const iterator = range(100); | ||
|
||
consume(iterator, 37); | ||
|
||
const output = list(iterator); | ||
|
||
t.deepEqual(output, list(range(37, 100))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import test from 'ava'; | ||
|
||
import {iter} from '@iterable-iterator/iter'; | ||
import {next} from '@iterable-iterator/next'; | ||
import {range} from '@iterable-iterator/range'; | ||
import {list} from '@iterable-iterator/list'; | ||
import {exhaust} from '../../src/index.js'; | ||
|
||
test('exhaust', (t) => { | ||
const iterator = iter(range(0, 100, 1)); | ||
|
||
const head = function* (iterator, n) { | ||
// eslint-disable-next-line no-unused-vars | ||
for (const _ of range(n)) yield next(iterator); | ||
}; | ||
|
||
exhaust(head(iterator, 37)); | ||
|
||
const output = list(iterator); | ||
|
||
t.deepEqual(output, list(range(37, 100, 1))); | ||
}); |