@jamashita/lluvia-sequence 2.6.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/ASequence.d.ts +4 -3
- package/dist/cjs/ASequence.d.ts.map +1 -1
- package/dist/cjs/ASequence.js +17 -28
- package/dist/cjs/ASequence.js.map +1 -1
- package/dist/cjs/ImmutableSequence.d.ts +5 -5
- package/dist/cjs/ImmutableSequence.d.ts.map +1 -1
- package/dist/cjs/ImmutableSequence.js +2 -2
- package/dist/cjs/ImmutableSequence.js.map +1 -1
- package/dist/cjs/MutableSequence.d.ts +8 -8
- package/dist/cjs/MutableSequence.d.ts.map +1 -1
- package/dist/cjs/MutableSequence.js +2 -2
- package/dist/cjs/MutableSequence.js.map +1 -1
- package/dist/cjs/ReadonlySequence.d.ts +3 -2
- package/dist/cjs/ReadonlySequence.d.ts.map +1 -1
- package/dist/cjs/Sequence.d.ts +2 -2
- package/dist/cjs/Sequence.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{Mock → mock}/MockSequence.d.ts +0 -0
- package/dist/{esm/Mock → cjs/mock}/MockSequence.d.ts.map +1 -1
- package/dist/cjs/{Mock → mock}/MockSequence.js +0 -0
- package/dist/cjs/{Mock → mock}/MockSequence.js.map +1 -1
- package/dist/cjs/mock/index.d.ts +2 -0
- package/dist/cjs/mock/index.d.ts.map +1 -0
- package/dist/cjs/mock/index.js +18 -0
- package/dist/cjs/mock/index.js.map +1 -0
- package/dist/esm/ASequence.d.ts +4 -3
- package/dist/esm/ASequence.d.ts.map +1 -1
- package/dist/esm/ASequence.js +17 -28
- package/dist/esm/ASequence.js.map +1 -1
- package/dist/esm/ImmutableSequence.d.ts +5 -5
- package/dist/esm/ImmutableSequence.d.ts.map +1 -1
- package/dist/esm/ImmutableSequence.js +2 -2
- package/dist/esm/ImmutableSequence.js.map +1 -1
- package/dist/esm/MutableSequence.d.ts +8 -8
- package/dist/esm/MutableSequence.d.ts.map +1 -1
- package/dist/esm/MutableSequence.js +2 -2
- package/dist/esm/MutableSequence.js.map +1 -1
- package/dist/esm/ReadonlySequence.d.ts +3 -2
- package/dist/esm/ReadonlySequence.d.ts.map +1 -1
- package/dist/esm/Sequence.d.ts +2 -2
- package/dist/esm/Sequence.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{Mock → mock}/MockSequence.d.ts +0 -0
- package/dist/{cjs/Mock → esm/mock}/MockSequence.d.ts.map +1 -1
- package/dist/esm/{Mock → mock}/MockSequence.js +0 -0
- package/dist/esm/{Mock → mock}/MockSequence.js.map +1 -1
- package/dist/esm/mock/index.d.ts +2 -0
- package/dist/esm/mock/index.d.ts.map +1 -0
- package/dist/esm/mock/index.js +2 -0
- package/dist/esm/mock/index.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -8
- package/src/ASequence.ts +22 -36
- package/src/ImmutableSequence.ts +20 -20
- package/src/MutableSequence.ts +17 -17
- package/src/ReadonlySequence.ts +4 -2
- package/src/Sequence.ts +2 -2
- package/src/__tests__/ASequence.spec.ts +227 -229
- package/src/__tests__/ImmutableSequence.spec.ts +231 -285
- package/src/__tests__/MutableSequence.spec.ts +210 -260
- package/src/index.ts +1 -1
- package/src/{Mock → mock}/MockSequence.ts +0 -0
- package/src/mock/index.ts +1 -0
package/src/ASequence.ts
CHANGED
@@ -3,10 +3,10 @@ import {
|
|
3
3
|
Ambiguous,
|
4
4
|
BinaryFunction,
|
5
5
|
BinaryPredicate,
|
6
|
-
|
6
|
+
ForEach,
|
7
7
|
isEqualable,
|
8
8
|
Kind,
|
9
|
-
|
9
|
+
Mapping,
|
10
10
|
Nullable
|
11
11
|
} from '@jamashita/anden-type';
|
12
12
|
import { Quantity } from '@jamashita/lluvia-collection';
|
@@ -26,7 +26,7 @@ export abstract class ASequence<V, T extends ASequence<V, T>> extends Quantity<n
|
|
26
26
|
|
27
27
|
public abstract override filter(predicate: BinaryPredicate<V, number>): T;
|
28
28
|
|
29
|
-
public abstract override map<W>(
|
29
|
+
public abstract override map<W>(mapping: Mapping<V, W>): Sequence<W>;
|
30
30
|
|
31
31
|
public abstract remove(key: number): T;
|
32
32
|
|
@@ -60,38 +60,20 @@ export abstract class ASequence<V, T extends ASequence<V, T>> extends Quantity<n
|
|
60
60
|
return false;
|
61
61
|
}
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
let tr: IteratorResult<V> = ti.next();
|
66
|
-
let or: IteratorResult<unknown> = oi.next();
|
67
|
-
|
68
|
-
while (tr.done !== true && or.done !== true) {
|
69
|
-
if (isEqualable(tr.value) && isEqualable(or.value)) {
|
70
|
-
if (!tr.value.equals(or.value)) {
|
71
|
-
return false;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
else if (tr.value !== or.value) {
|
75
|
-
return false;
|
76
|
-
}
|
77
|
-
|
78
|
-
tr = ti.next();
|
79
|
-
or = oi.next();
|
80
|
-
|
81
|
-
if (tr.done === true && or.done === true) {
|
63
|
+
return this.sequence.every((v: V, i: number) => {
|
64
|
+
if (v === other.sequence[i]) {
|
82
65
|
return true;
|
83
66
|
}
|
84
|
-
|
67
|
+
if (isEqualable(v)) {
|
68
|
+
return v.equals(other.sequence[i]);
|
69
|
+
}
|
85
70
|
|
86
|
-
|
71
|
+
return false;
|
72
|
+
});
|
87
73
|
}
|
88
74
|
|
89
75
|
public every(predicate: BinaryPredicate<V, number>): boolean {
|
90
|
-
|
91
|
-
return !predicate(v, i);
|
92
|
-
});
|
93
|
-
|
94
|
-
return Kind.isUndefined(found);
|
76
|
+
return this.sequence.every(predicate);
|
95
77
|
}
|
96
78
|
|
97
79
|
protected filterInternal(predicate: BinaryPredicate<V, number>): Array<V> {
|
@@ -116,10 +98,8 @@ export abstract class ASequence<V, T extends ASequence<V, T>> extends Quantity<n
|
|
116
98
|
return found;
|
117
99
|
}
|
118
100
|
|
119
|
-
public forEach(
|
120
|
-
this.sequence.forEach(
|
121
|
-
catalogue(v, i);
|
122
|
-
});
|
101
|
+
public forEach(foreach: ForEach<number, V>): void {
|
102
|
+
this.sequence.forEach(foreach);
|
123
103
|
}
|
124
104
|
|
125
105
|
public get(key: number): Nullable<V> {
|
@@ -138,6 +118,14 @@ export abstract class ASequence<V, T extends ASequence<V, T>> extends Quantity<n
|
|
138
118
|
}).values();
|
139
119
|
}
|
140
120
|
|
121
|
+
public reduce(reducer: BinaryFunction<V, V, V>, initialValue?: V): V {
|
122
|
+
if (Kind.isUndefined(initialValue)) {
|
123
|
+
return this.sequence.reduce(reducer);
|
124
|
+
}
|
125
|
+
|
126
|
+
return this.sequence.reduce(reducer, initialValue);
|
127
|
+
}
|
128
|
+
|
141
129
|
protected removeInternal(key: number): Array<V> {
|
142
130
|
if (!Kind.isInteger(key)) {
|
143
131
|
return this.sequence;
|
@@ -171,9 +159,7 @@ export abstract class ASequence<V, T extends ASequence<V, T>> extends Quantity<n
|
|
171
159
|
}
|
172
160
|
|
173
161
|
public some(predicate: BinaryPredicate<V, number>): boolean {
|
174
|
-
|
175
|
-
|
176
|
-
return !Kind.isUndefined(found);
|
162
|
+
return this.sequence.some(predicate);
|
177
163
|
}
|
178
164
|
|
179
165
|
public toArray(): Array<V> {
|
package/src/ImmutableSequence.ts
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import { BinaryFunction, BinaryPredicate,
|
1
|
+
import { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden-type';
|
2
2
|
import { Collection } from '@jamashita/lluvia-collection';
|
3
3
|
import { ASequence } from './ASequence';
|
4
4
|
|
5
5
|
export class ImmutableSequence<V> extends ASequence<V, ImmutableSequence<V>> {
|
6
6
|
private static readonly EMPTY: ImmutableSequence<unknown> = new ImmutableSequence<unknown>([]);
|
7
7
|
|
8
|
-
public static empty<
|
9
|
-
return ImmutableSequence.EMPTY as ImmutableSequence<
|
8
|
+
public static empty<V>(): ImmutableSequence<V> {
|
9
|
+
return ImmutableSequence.EMPTY as ImmutableSequence<V>;
|
10
10
|
}
|
11
11
|
|
12
|
-
public static of<
|
13
|
-
return ImmutableSequence.ofInternal
|
12
|
+
public static of<V>(collection: Collection<number, V>): ImmutableSequence<V> {
|
13
|
+
return ImmutableSequence.ofInternal([...collection.values()]);
|
14
14
|
}
|
15
15
|
|
16
|
-
public static ofArray<
|
17
|
-
return ImmutableSequence.ofInternal
|
16
|
+
public static ofArray<V>(array: ReadonlyArray<V>): ImmutableSequence<V> {
|
17
|
+
return ImmutableSequence.ofInternal([...array]);
|
18
18
|
}
|
19
19
|
|
20
|
-
private static ofInternal<
|
20
|
+
private static ofInternal<V>(array: Array<V>): ImmutableSequence<V> {
|
21
21
|
if (array.length === 0) {
|
22
|
-
return ImmutableSequence.empty
|
22
|
+
return ImmutableSequence.empty();
|
23
23
|
}
|
24
24
|
|
25
|
-
return new ImmutableSequence
|
25
|
+
return new ImmutableSequence(array);
|
26
26
|
}
|
27
27
|
|
28
28
|
protected constructor(sequence: Array<V>) {
|
@@ -30,31 +30,31 @@ export class ImmutableSequence<V> extends ASequence<V, ImmutableSequence<V>> {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
public add(value: V): ImmutableSequence<V> {
|
33
|
-
return ImmutableSequence.ofArray
|
33
|
+
return ImmutableSequence.ofArray([...this.sequence, value]);
|
34
34
|
}
|
35
35
|
|
36
36
|
public duplicate(): ImmutableSequence<V> {
|
37
37
|
if (this.isEmpty()) {
|
38
|
-
return ImmutableSequence.empty
|
38
|
+
return ImmutableSequence.empty();
|
39
39
|
}
|
40
40
|
|
41
|
-
return ImmutableSequence.ofArray
|
41
|
+
return ImmutableSequence.ofArray([...this.sequence]);
|
42
42
|
}
|
43
43
|
|
44
44
|
public filter(predicate: BinaryPredicate<V, number>): ImmutableSequence<V> {
|
45
|
-
return ImmutableSequence.ofArray
|
45
|
+
return ImmutableSequence.ofArray(this.filterInternal(predicate));
|
46
46
|
}
|
47
47
|
|
48
48
|
public override isEmpty(): boolean {
|
49
|
-
if (this === ImmutableSequence.empty
|
49
|
+
if (this === ImmutableSequence.empty()) {
|
50
50
|
return true;
|
51
51
|
}
|
52
52
|
|
53
53
|
return super.isEmpty();
|
54
54
|
}
|
55
55
|
|
56
|
-
public map<W>(
|
57
|
-
return ImmutableSequence.ofArray
|
56
|
+
public map<W>(mapping: Mapping<V, W>): ImmutableSequence<W> {
|
57
|
+
return ImmutableSequence.ofArray(this.sequence.map(mapping));
|
58
58
|
}
|
59
59
|
|
60
60
|
public remove(key: number): ImmutableSequence<V> {
|
@@ -64,7 +64,7 @@ export class ImmutableSequence<V> extends ASequence<V, ImmutableSequence<V>> {
|
|
64
64
|
return this;
|
65
65
|
}
|
66
66
|
|
67
|
-
return ImmutableSequence.ofArray
|
67
|
+
return ImmutableSequence.ofArray(sequence);
|
68
68
|
}
|
69
69
|
|
70
70
|
public set(key: number, value: V): ImmutableSequence<V> {
|
@@ -74,7 +74,7 @@ export class ImmutableSequence<V> extends ASequence<V, ImmutableSequence<V>> {
|
|
74
74
|
return this;
|
75
75
|
}
|
76
76
|
|
77
|
-
return ImmutableSequence.ofArray
|
77
|
+
return ImmutableSequence.ofArray(sequence);
|
78
78
|
}
|
79
79
|
|
80
80
|
public sort(comparator: BinaryFunction<V, V, number>): ImmutableSequence<V> {
|
@@ -82,6 +82,6 @@ export class ImmutableSequence<V> extends ASequence<V, ImmutableSequence<V>> {
|
|
82
82
|
|
83
83
|
arr.sort(comparator);
|
84
84
|
|
85
|
-
return ImmutableSequence.ofArray
|
85
|
+
return ImmutableSequence.ofArray(arr);
|
86
86
|
}
|
87
87
|
}
|
package/src/MutableSequence.ts
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
import { BinaryFunction, BinaryPredicate,
|
1
|
+
import { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden-type';
|
2
2
|
import { Collection } from '@jamashita/lluvia-collection';
|
3
3
|
import { ASequence } from './ASequence';
|
4
4
|
|
5
5
|
export class MutableSequence<V> extends ASequence<V, MutableSequence<V>> {
|
6
|
-
public static empty<
|
7
|
-
return MutableSequence.ofArray
|
6
|
+
public static empty<V>(): MutableSequence<V> {
|
7
|
+
return MutableSequence.ofArray([]);
|
8
8
|
}
|
9
9
|
|
10
|
-
public static of<
|
11
|
-
return MutableSequence.ofInternal
|
10
|
+
public static of<V>(collection: Collection<number, V>): MutableSequence<V> {
|
11
|
+
return MutableSequence.ofInternal([...collection.values()]);
|
12
12
|
}
|
13
13
|
|
14
|
-
public static ofArray<
|
15
|
-
return MutableSequence.ofInternal
|
14
|
+
public static ofArray<V>(array: ReadonlyArray<V>): MutableSequence<V> {
|
15
|
+
return MutableSequence.ofInternal([...array]);
|
16
16
|
}
|
17
17
|
|
18
|
-
private static ofInternal<
|
19
|
-
return new MutableSequence
|
18
|
+
private static ofInternal<V>(array: Array<V>): MutableSequence<V> {
|
19
|
+
return new MutableSequence(array);
|
20
20
|
}
|
21
21
|
|
22
22
|
protected constructor(sequence: Array<V>) {
|
23
23
|
super(sequence);
|
24
24
|
}
|
25
25
|
|
26
|
-
public add(value: V):
|
26
|
+
public add(value: V): this {
|
27
27
|
this.sequence.push(value);
|
28
28
|
|
29
29
|
return this;
|
30
30
|
}
|
31
31
|
|
32
32
|
public duplicate(): MutableSequence<V> {
|
33
|
-
return MutableSequence.ofArray
|
33
|
+
return MutableSequence.ofArray([...this.sequence]);
|
34
34
|
}
|
35
35
|
|
36
36
|
public filter(predicate: BinaryPredicate<V, number>): MutableSequence<V> {
|
37
|
-
return MutableSequence.ofArray
|
37
|
+
return MutableSequence.ofArray(this.filterInternal(predicate));
|
38
38
|
}
|
39
39
|
|
40
|
-
public map<W>(
|
41
|
-
return MutableSequence.ofArray
|
40
|
+
public map<W>(mapping: Mapping<V, W>): MutableSequence<W> {
|
41
|
+
return MutableSequence.ofArray(this.sequence.map(mapping));
|
42
42
|
}
|
43
43
|
|
44
|
-
public remove(key: number):
|
44
|
+
public remove(key: number): this {
|
45
45
|
this.sequence = this.removeInternal(key);
|
46
46
|
|
47
47
|
return this;
|
48
48
|
}
|
49
49
|
|
50
|
-
public set(key: number, value: V):
|
50
|
+
public set(key: number, value: V): this {
|
51
51
|
this.sequence = this.setInternal(key, value);
|
52
52
|
|
53
53
|
return this;
|
@@ -58,6 +58,6 @@ export class MutableSequence<V> extends ASequence<V, MutableSequence<V>> {
|
|
58
58
|
|
59
59
|
arr.sort(comparator);
|
60
60
|
|
61
|
-
return MutableSequence.ofArray
|
61
|
+
return MutableSequence.ofArray(arr);
|
62
62
|
}
|
63
63
|
}
|
package/src/ReadonlySequence.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BinaryFunction, BinaryPredicate, Cloneable,
|
1
|
+
import { BinaryFunction, BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden-type';
|
2
2
|
import { Collection } from '@jamashita/lluvia-collection';
|
3
3
|
|
4
4
|
export interface ReadonlySequence<V> extends Collection<number, V>, Cloneable<ReadonlySequence<V>> {
|
@@ -6,7 +6,9 @@ export interface ReadonlySequence<V> extends Collection<number, V>, Cloneable<Re
|
|
6
6
|
|
7
7
|
iterator(): IterableIterator<[number, V]>;
|
8
8
|
|
9
|
-
map<W>(
|
9
|
+
map<W>(mapping: Mapping<V, W>): ReadonlySequence<W>;
|
10
|
+
|
11
|
+
reduce(reducer: BinaryFunction<V, V, V>, initialValue?: V): V;
|
10
12
|
|
11
13
|
sort(comparator: BinaryFunction<V, V, number>): ReadonlySequence<V>;
|
12
14
|
|
package/src/Sequence.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BinaryPredicate,
|
1
|
+
import { BinaryPredicate, Mapping } from '@jamashita/anden-type';
|
2
2
|
import { ReadonlySequence } from './ReadonlySequence';
|
3
3
|
|
4
4
|
export interface Sequence<V> extends ReadonlySequence<V> {
|
@@ -6,7 +6,7 @@ export interface Sequence<V> extends ReadonlySequence<V> {
|
|
6
6
|
|
7
7
|
filter(predicate: BinaryPredicate<V, number>): Sequence<V>;
|
8
8
|
|
9
|
-
map<W>(
|
9
|
+
map<W>(mapping: Mapping<V, W>): Sequence<W>;
|
10
10
|
|
11
11
|
remove(key: number): Sequence<V>;
|
12
12
|
|