Skip to content

Commit a68de81

Browse files
♻️ refactor(Deep): Simplify #append.
1 parent 7e1f2b1 commit a68de81

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/3-tree/implementations/2-Deep.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {deepL, deepR, CachedMeasure, Split} from '../../0-core/index.js';
44
import {One, Two, Three, Four} from '../../1-digit/index.js';
55
import Lazy from '../../4-lazy/Lazy.js';
66
import _prepend_small_list from '../../0-core/_fast/_prepend_small_list.js';
7-
import _fill_right from '../../0-core/_fast/_fill_right.js';
87
import isSameMeasure from '../../_debug/isSameMeasure.js';
9-
import _append_small_list from '../../0-core/_fast/_append_small_list.js';
108
import _from_by_filling from '../../0-core/_fast/_from_by_filling.js';
119
import empty from '../../5-api/empty.js';
1210
import delayApp3RecurseStep from '../../4-lazy/delayApp3RecurseStep.js';
@@ -92,25 +90,7 @@ Deep.prototype.prepend = function (iterable) {
9290
};
9391

9492
Deep.prototype.append = function (iterable) {
95-
const it = iterable[Symbol.iterator]();
96-
97-
let event = it.next();
98-
if (event.done) return this;
99-
const a = event.value;
100-
101-
event = it.next();
102-
if (event.done) return this.push(a);
103-
const b = event.value;
104-
105-
// TODO simplify
106-
const middle = _append_small_list(
107-
this._middle,
108-
this._right._nodes(this.M, new One(a)),
109-
)._copy_spine();
110-
// TODO _copy_spine should return a MutableDeep type on the spine
111-
// TODO then _fill_right should only accept Empty, Single, or MutableDeep
112-
113-
return _fill_right(this.M, this._left, middle, b, it);
93+
return this.concat(_from_by_filling(this.M, iterable));
11494
};
11595

11696
Deep.prototype.concat = function (other) {

0 commit comments

Comments
 (0)