Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: Use default exports everywhere.
Fix some function signatures, remove some circular dependencies.
- Loading branch information
1 parent
66fc104
commit b63b59f
Showing
73 changed files
with
358 additions
and
274 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,21 @@ | ||
import assert from 'assert'; | ||
import iter from './iter.js'; | ||
import consume from './consume.js'; | ||
|
||
/** | ||
* Drops the first <code>n</code> values of the input iterable. | ||
* | ||
* @example | ||
* // returns [ 3 , 4 ] | ||
* list( _drop( range( 5 ) , 3 ) ) ; | ||
* | ||
* @param {Iterable} iterable - The input iterable. | ||
* @param {Number} n - The nonnegative number of values to drop. | ||
* @returns {IterableIterator} - The remaining values of the input iterable. | ||
*/ | ||
export default function* _drop(iterable, n) { | ||
assert(Number.isInteger(n) && n >= 0); | ||
const iterator = iter(iterable); | ||
consume(iterator, n); | ||
yield* 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
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,18 @@ | ||
import assert from 'assert'; | ||
import deque from '@aureooms/js-collections-deque'; | ||
|
||
/** | ||
* Returns the last <code>n</code> values of the input iterable in an array. | ||
* | ||
* @example | ||
* // returns [ 3 , 4 ] | ||
* list( _tail( range( 5 ) , 2 ) ) ; | ||
* | ||
* @param {Iterable} iterable - The input iterable. | ||
* @param {Number} n - The nonnegative number of values to include in the output. | ||
* @returns {IterableIterator} - The last <code>n</code> values of the input iterable. | ||
*/ | ||
export default function* _tail(iterable, n) { | ||
assert(Number.isInteger(n) && n >= 0); | ||
yield* deque(iterable, n); | ||
} |
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,29 @@ | ||
import assert from 'assert'; | ||
import iter from './iter.js'; | ||
|
||
/** | ||
* Yields the first <code>n</code> elements of the input iterable. | ||
* | ||
* @example | ||
* // returns [ 0 , 1 , 2 ] | ||
* list( _take( range( 5 ) , 3 ) ) ; | ||
* | ||
* @param {Iterable} iterable - The input iterable. | ||
* @param {Number} n - The nonnegative number of elements to include in the output. | ||
* @returns {IterableIterator} - The first <code>n</code> elements of the input iterable. | ||
*/ | ||
export default function* _take(iterable, n) { | ||
assert(Number.isInteger(n) && n >= 0); | ||
|
||
const iterator = iter(iterable); | ||
|
||
while (n-- > 0) { | ||
const current = iterator.next(); | ||
|
||
if (current.done) { | ||
return; | ||
} | ||
|
||
yield current.value; | ||
} | ||
} |
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,42 @@ | ||
import assert from 'assert'; | ||
import deque from '@aureooms/js-collections-deque'; | ||
|
||
import iter from './iter.js'; | ||
|
||
/** | ||
* Yields all elements of the iterable except the last <code>n</code> ones. | ||
* | ||
* @example | ||
* // returns [ 0 , 1 , 2 ] | ||
* list( _trunc( range( 5 ) , 2 ) ) ; | ||
* | ||
* @param {Iterable} iterable - The input iterable. | ||
* @param {Number} n - The nonnegative number of elements to exclude from the output. | ||
* @returns {IterableIterator} | ||
*/ | ||
export default function* _trunc(iterable, n) { | ||
assert(Number.isInteger(n) && n >= 0); | ||
|
||
if (n === 0) { | ||
yield* iterable; | ||
return; | ||
} | ||
|
||
const iterator = iter(iterable); | ||
|
||
const buffer = deque(null, n); | ||
|
||
while (n-- > 0) { | ||
const event = iterator.next(); | ||
if (event.done) { | ||
return; | ||
} | ||
|
||
buffer.append(event.value); | ||
} | ||
|
||
for (const value of iterator) { | ||
yield buffer.popleft(); | ||
buffer.append(value); | ||
} | ||
} |
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
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
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,7 +1,8 @@ | ||
import {next} from './next.js'; | ||
import next from './next.js'; | ||
|
||
/** | ||
* Same as {@link next}. | ||
* @function first | ||
*/ | ||
export const first = next; | ||
const first = next; | ||
export default first; |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import {take} from './take.js'; | ||
import take from './take.js'; | ||
|
||
/** | ||
* Same as {@link take}. | ||
* @function head | ||
*/ | ||
export const head = take; | ||
const head = take; | ||
export default head; |
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
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 |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
* @returns {Number} | ||
* | ||
*/ | ||
export function len(array) { | ||
export default function len(array) { | ||
return array.length; | ||
} |
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
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
Oops, something went wrong.