Skip to content

Commit a1f9ae6

Browse files
💥 refactor!: Rename #empty to #isEmpty.
BREAKING CHANGE: This breaks any dependent relying on the old API.
1 parent 2dad5b7 commit a1f9ae6

File tree

9 files changed

+50
-22
lines changed

9 files changed

+50
-22
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Parent is [@aureooms/js-persistent](https://github.com/aureooms/js-persistent).
4141
* [`from(Measure, Iterable) -> Tree`](#frommeasure-iterable---tree)
4242
* [:question: Predicates](#question-predicates)
4343
* [`Tree#measure() -> m`](#treemeasure---m)
44-
* [`Tree#empty() -> Boolean`](#treeempty---boolean)
44+
* [`Tree#isEmpty() -> Boolean`](#treeisempty---boolean)
4545
* [:salt: Add values](#salt-add-values)
4646
* [`Tree#push(x) -> Tree`](#treepushx---tree)
4747
* [`Tree#cons(x) -> Tree`](#treeconsx---tree)
@@ -161,12 +161,12 @@ Returns the measure of the tree.
161161
if ( tree.measure() > 1 ) ...
162162
```
163163

164-
#### `Tree#empty() -> Boolean`
164+
#### `Tree#isEmpty() -> Boolean`
165165

166166
Returns `true` if the tree is empty, `false` otherwise.
167167

168168
```js
169-
return tree.empty() ? 'empty' : 'not empty' ;
169+
return tree.isEmpty() ? 'empty' : 'not empty' ;
170170
```
171171

172172

@@ -228,15 +228,15 @@ let last = tree.last() ; // 'b'
228228
Returns a new tree without the right-most value.
229229

230230
```js
231-
while ( ! tree.empty() ) tree = tree.init() ;
231+
while ( ! tree.isEmpty() ) tree = tree.init() ;
232232
```
233233

234234
#### `Tree#tail() -> Tree`
235235

236236
Returns a new tree without the left-most value.
237237

238238
```js
239-
while ( ! tree.empty() ) tree = tree.tail() ;
239+
while ( ! tree.isEmpty() ) tree = tree.tail() ;
240240
```
241241

242242

src/0-core/split/deepL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {_from_digit, _digit} from '../_fast/index.js';
1010
*/
1111
export function deepL(M, left, middle, right) {
1212
if (left.length === 0) {
13-
if (middle.empty()) return _from_digit(M, right);
13+
if (middle.isEmpty()) return _from_digit(M, right);
1414

1515
return new Deep(
1616
M,

src/0-core/split/deepR.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {_from_digit, _digit} from '../_fast/index.js';
1010
*/
1111
export function deepR(M, left, middle, right) {
1212
if (right.length === 0) {
13-
if (middle.empty()) return _from_digit(M, left);
13+
if (middle.isEmpty()) return _from_digit(M, left);
1414

1515
return new Deep(
1616
M,

src/3-tree/implementations/0-Empty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Empty.prototype.measure = function () {
1313
return this.v;
1414
};
1515

16-
Empty.prototype.empty = function () {
16+
Empty.prototype.isEmpty = function () {
1717
return true;
1818
};
1919

src/3-tree/implementations/1-Single.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Single.prototype.measure = function () {
1515
return this.v;
1616
};
1717

18-
Single.prototype.empty = function () {
18+
Single.prototype.isEmpty = function () {
1919
return false;
2020
};
2121

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Deep.prototype.measure = function () {
3838
return this.v;
3939
};
4040

41-
Deep.prototype.empty = function () {
41+
Deep.prototype.isEmpty = function () {
4242
return false;
4343
};
4444

@@ -52,7 +52,7 @@ Deep.prototype.last = function () {
5252

5353
Deep.prototype.tail = function () {
5454
if (this.left instanceof One) {
55-
if (this.middle.empty()) {
55+
if (this.middle.isEmpty()) {
5656
return _from_digit(this.M, this.right);
5757
}
5858

@@ -69,7 +69,7 @@ Deep.prototype.tail = function () {
6969

7070
Deep.prototype.init = function () {
7171
if (this.right instanceof One) {
72-
if (this.middle.empty()) {
72+
if (this.middle.isEmpty()) {
7373
return _from_digit(this.M, this.left);
7474
}
7575

src/4-lazy/0-Lazy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Lazy.prototype.force = function () {
1616
return this.tree;
1717
};
1818

19-
Lazy.prototype.empty = function () {
20-
return this.force().empty();
19+
Lazy.prototype.isEmpty = function () {
20+
return this.force().isEmpty();
2121
};
2222

2323
Lazy.prototype.measure = function () {

test/src/FingerTree.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ test('FingerTree', (t) => {
6565
.concat(V4)
6666
.concat(EMPTY);
6767

68-
t.true(EMPTY.empty());
69-
t.true(!V.empty());
70-
t.true(V1.tail().empty());
71-
t.true(V1.init().empty());
72-
t.true(V4.tail().empty());
73-
t.true(V4.init().empty());
74-
t.true(EMPTY.tail().empty());
75-
t.true(EMPTY.init().empty());
68+
t.true(EMPTY.isEmpty());
69+
t.true(!V.isEmpty());
70+
t.true(V1.tail().isEmpty());
71+
t.true(V1.init().isEmpty());
72+
t.true(V4.tail().isEmpty());
73+
t.true(V4.init().isEmpty());
74+
t.true(EMPTY.tail().isEmpty());
75+
t.true(EMPTY.init().isEmpty());
7676
t.is(V.measure(), M);
7777
t.is(V.head(), 0);
7878
t.is(V.last(), M - 1);

test/src/methods/isEmpty.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@aureooms/js-measure';
4+
const {COUNTER} = Measures;
5+
6+
import {range} from '@aureooms/js-itertools';
7+
8+
import {empty, from} from '../../../src/index.js';
9+
10+
test('empty(COUNTER) is empty', (t) => {
11+
t.true(empty(COUNTER).isEmpty());
12+
});
13+
14+
test('from(COUNTER, []) is empty', (t) => {
15+
t.true(from(COUNTER, []).isEmpty());
16+
});
17+
18+
test('from(COUNTER, range(0)) is empty', (t) => {
19+
t.true(from(COUNTER, range(0)).isEmpty());
20+
});
21+
22+
test('from(COUNTER, [0]) is not empty', (t) => {
23+
t.false(from(COUNTER, [0]).isEmpty());
24+
});
25+
26+
test('from(COUNTER, range(1000)) is not empty', (t) => {
27+
t.false(from(COUNTER, range(1000)).isEmpty());
28+
});

0 commit comments

Comments
 (0)