Skip to content

Commit d9681d8

Browse files
♻️ refactor: Remove empty Digit base class.
1 parent 4e24c9c commit d9681d8

File tree

9 files changed

+62
-29
lines changed

9 files changed

+62
-29
lines changed

src/0-core/split/DigitSplit.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import assert from 'assert';
2-
import {Digit} from '../../1-digit/0-Digit.js';
2+
import {One} from '../../1-digit/1-One.js';
3+
import {Two} from '../../1-digit/2-Two.js';
4+
import {Three} from '../../1-digit/3-Three.js';
5+
import {Four} from '../../1-digit/4-Four.js';
36

47
/**
58
* DigitSplit.
69
*
7-
* @param {Digit} left
10+
* @param {null|One|Two|Three|Four} left
811
* @param {any} middle
9-
* @param {Digit} right
12+
* @param {null|One|Two|Three|Four} right
1013
*/
1114
export function DigitSplit(left, middle, right) {
12-
assert(left === null || left instanceof Digit);
13-
assert(right === null || right instanceof Digit);
15+
assert(
16+
left === null ||
17+
left instanceof One ||
18+
left instanceof Two ||
19+
left instanceof Three ||
20+
left instanceof Four,
21+
);
22+
assert(
23+
right === null ||
24+
right instanceof One ||
25+
right instanceof Two ||
26+
right instanceof Three ||
27+
right instanceof Four,
28+
);
1429
this._left = left;
1530
this._middle = middle;
1631
this._right = right;

src/0-core/split/deepL.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import assert from 'assert';
22

3-
import {Digit} from '../../1-digit/0-Digit.js';
3+
import {One} from '../../1-digit/1-One.js';
4+
import {Two} from '../../1-digit/2-Two.js';
5+
import {Three} from '../../1-digit/3-Three.js';
6+
import {Four} from '../../1-digit/4-Four.js';
47
import {Deep, Tree} from '../../3-tree/index.js';
58
import delayTail from '../../4-lazy/delayTail.js';
69

710
/**
811
* @param {any} M
9-
* @param {Digit|null} left
12+
* @param {null|One|Two|Three|Four} left
1013
* @param {Tree} middle
11-
* @param {Digit} right
14+
* @param {One|Two|Three|Four} right
1215
*/
1316
export function deepL(M, left, middle, right) {
14-
assert(left === null || left instanceof Digit);
17+
assert(
18+
left === null ||
19+
left instanceof One ||
20+
left instanceof Two ||
21+
left instanceof Three ||
22+
left instanceof Four,
23+
);
1524
assert(middle instanceof Tree);
16-
assert(right instanceof Digit);
25+
assert(
26+
right instanceof One ||
27+
right instanceof Two ||
28+
right instanceof Three ||
29+
right instanceof Four,
30+
);
1731

1832
if (left === null) {
1933
if (middle.isEmpty()) return right._tree(M);

src/0-core/split/deepR.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import assert from 'assert';
22

3-
import {Digit} from '../../1-digit/0-Digit.js';
3+
import {One} from '../../1-digit/1-One.js';
4+
import {Two} from '../../1-digit/2-Two.js';
5+
import {Three} from '../../1-digit/3-Three.js';
6+
import {Four} from '../../1-digit/4-Four.js';
47
import {Deep, Tree} from '../../3-tree/index.js';
58
import delayInit from '../../4-lazy/delayInit.js';
69

710
/**
811
* @param {any} M
9-
* @param {Digit} left
12+
* @param {One|Two|Three|Four} left
1013
* @param {Tree} middle
11-
* @param {Digit|null} right
14+
* @param {null|One|Two|Three|Four} right
1215
*/
1316
export function deepR(M, left, middle, right) {
14-
assert(left instanceof Digit);
17+
assert(
18+
left instanceof One ||
19+
left instanceof Two ||
20+
left instanceof Three ||
21+
left instanceof Four,
22+
);
1523
assert(middle instanceof Tree);
16-
assert(right === null || right instanceof Digit);
24+
assert(
25+
right === null ||
26+
right instanceof One ||
27+
right instanceof Two ||
28+
right instanceof Three ||
29+
right instanceof Four,
30+
);
1731

1832
if (right === null) {
1933
if (middle.isEmpty()) return left._tree(M);

src/1-digit/0-Digit.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/1-digit/1-One.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import {Single} from '../3-tree/implementations/1-Single.js';
55
import {Deep} from '../3-tree/implementations/2-Deep.js';
66
import delayTail from '../4-lazy/delayTail.js';
77
import delayInit from '../4-lazy/delayInit.js';
8-
import {Digit, Two, Three, Four} from './index.js';
8+
import {Two, Three, Four} from './index.js';
99

1010
export function One(a) {
1111
this.a = a;
1212
this.v = null;
1313
}
1414

15-
One.prototype = new Digit();
16-
1715
One.prototype.measure = function (M) {
1816
if (this.v === null) this.v = M.measure(this.a);
1917
return this.v;

src/1-digit/2-Two.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import {DigitSplit} from '../0-core/split/DigitSplit.js';
44
import empty from '../5-api/empty.js';
55
import {cache} from '../0-core/measure/cache.js';
66
import {Deep} from '../3-tree/implementations/2-Deep.js';
7-
import {Digit, One, Three, Four} from './index.js';
7+
import {One, Three, Four} from './index.js';
88

99
export function Two(a, b) {
1010
this.a = a;
1111
this.b = b;
1212
this.v = null;
1313
}
1414

15-
Two.prototype = new Digit();
16-
1715
Two.prototype.measure = function (M) {
1816
if (this.v === null) this.v = M.plus(M.measure(this.a), M.measure(this.b));
1917
return this.v;

src/1-digit/3-Three.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {DigitSplit} from '../0-core/split/DigitSplit.js';
44
import empty from '../5-api/empty.js';
55
import {cache} from '../0-core/measure/cache.js';
66
import {Deep} from '../3-tree/implementations/2-Deep.js';
7-
import {Digit, One, Two, Four} from './index.js';
7+
import {One, Two, Four} from './index.js';
88

99
export function Three(a, b, c) {
1010
this.a = a;
@@ -13,8 +13,6 @@ export function Three(a, b, c) {
1313
this.v = null;
1414
}
1515

16-
Three.prototype = new Digit();
17-
1816
Three.prototype.measure = function (M) {
1917
if (this.v === null)
2018
this.v = M.plus(

src/1-digit/4-Four.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {DigitSplit} from '../0-core/split/DigitSplit.js';
44
import {node2, node3} from '../2-node/index.js';
55
import empty from '../5-api/empty.js';
66
import {Deep} from '../3-tree/implementations/2-Deep.js';
7-
import {Digit, One, Two, Three} from './index.js';
7+
import {One, Two, Three} from './index.js';
88

99
export function Four(a, b, c, d) {
1010
this.a = a;
@@ -14,8 +14,6 @@ export function Four(a, b, c, d) {
1414
this.v = null;
1515
}
1616

17-
Four.prototype = new Digit();
18-
1917
Four.prototype.measure = function (M) {
2018
if (this.v === null)
2119
this.v = M.plus(

src/1-digit/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './0-Digit.js';
21
export * from './1-One.js';
32
export * from './2-Two.js';
43
export * from './3-Three.js';

0 commit comments

Comments
 (0)