Skip to content

Commit

Permalink
♻️ refactor: Extract _extend from from.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Nov 13, 2022
1 parent 0972944 commit d3e6cf9
Showing 3 changed files with 24 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/_extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import assert from 'assert';
import Node from './Node.js';
import _push from './_push.js';

/**
* Extend a list with an iterable.
*
* @param {Node} z The last node of the list to extend.
* @param {Iterable} iterable The input iterable.
* @return {Node} Last node of the extended list.
*/
export default function _extend(z, iterable) {
assert(z instanceof Node);
let y = z;

for (const value of iterable) {
y = _push(y, value);
}

return y;
}
9 changes: 2 additions & 7 deletions src/from.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node from './Node.js';
import _push from './_push.js';
import _extend from './_extend.js';

/**
* Creates a list from an input iterable.
@@ -14,11 +14,6 @@ export default function from(iterable) {
if (event.done) return null;

const first = new Node(event.value, null, null);
let last = first;

for (const value of it) {
last = _push(last, value);
}

_extend(first, it);
return first;
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {default as Node} from './Node.js';
export {default as _concat} from './_concat.js';
export {default as _extend} from './_extend.js';
export {default as _iter} from './_iter.js';
export {default as _iter_fast} from './_iter_fast.js';
export {default as _last} from './_last.js';

0 comments on commit d3e6cf9

Please sign in to comment.