Skip to content

Commit df12c00

Browse files
authored
BREAKING: Remove Seq.of() (immutable-js#1311)
This function causes type safety issues as Seq is a baseclass and superclass methods also include .of(). `Seq.of(a, b)` can always be safely replaced with `Seq.Indexed.of(a, b)` or `Seq([a, b])`. Fixes immutable-js#1308
1 parent cb3b3ce commit df12c00

22 files changed

+121
-152
lines changed

__tests__/ArraySeq.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('ArraySequence', () => {
4040
});
4141

4242
it('counts from the end of the sequence on negative index', () => {
43-
let i = Seq.of(1, 2, 3, 4, 5, 6, 7);
43+
let i = Seq([1, 2, 3, 4, 5, 6, 7]);
4444
expect(i.get(-1)).toBe(7);
4545
expect(i.get(-5)).toBe(3);
4646
expect(i.get(-9)).toBe(undefined);

__tests__/Equality.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ describe('Equality', () => {
8585
});
8686

8787
it('compares sequences', () => {
88-
let arraySeq = Seq.of(1, 2, 3);
88+
let arraySeq = Seq([1, 2, 3]);
8989
let arraySeq2 = Seq([1, 2, 3]);
9090
expectIs(arraySeq, arraySeq);
91-
expectIs(arraySeq, Seq.of(1, 2, 3));
91+
expectIs(arraySeq, Seq([1, 2, 3]));
9292
expectIs(arraySeq2, arraySeq2);
9393
expectIs(arraySeq2, Seq([1, 2, 3]));
9494
expectIsNot(arraySeq, [1, 2, 3]);
@@ -99,12 +99,12 @@ describe('Equality', () => {
9999
});
100100

101101
it('compares lists', () => {
102-
let list = List.of(1, 2, 3);
102+
let list = List([1, 2, 3]);
103103
expectIs(list, list);
104104
expectIsNot(list, [1, 2, 3]);
105105

106-
expectIs(list, Seq.of(1, 2, 3));
107-
expectIs(list, List.of(1, 2, 3));
106+
expectIs(list, Seq([1, 2, 3]));
107+
expectIs(list, List([1, 2, 3]));
108108

109109
let listLonger = list.push(4);
110110
expectIsNot(list, listLonger);
@@ -135,9 +135,9 @@ describe('Equality', () => {
135135

136136
it('differentiates decimals', () => {
137137
expect(
138-
Seq.of(1.5).hashCode(),
138+
Seq([1.5]).hashCode(),
139139
).not.toBe(
140-
Seq.of(1.6).hashCode(),
140+
Seq([1.6]).hashCode(),
141141
);
142142
});
143143

__tests__/Seq.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ describe('Seq', () => {
2828
expect(Seq(new Foo()).size).toBe(2);
2929
});
3030

31-
it('of accepts varargs', () => {
32-
expect(Seq.of(1, 2, 3).size).toBe(3);
33-
});
34-
3531
it('accepts another sequence', () => {
36-
let seq = Seq.of(1, 2, 3);
32+
let seq = Seq([1, 2, 3]);
3733
expect(Seq(seq).size).toBe(3);
3834
});
3935

@@ -59,7 +55,7 @@ describe('Seq', () => {
5955
});
6056

6157
it('detects sequences', () => {
62-
let seq = Seq.of(1, 2, 3);
58+
let seq = Seq([1, 2, 3]);
6359
expect(Seq.isSeq(seq)).toBe(true);
6460
expect(isCollection(seq)).toBe(true);
6561
});

__tests__/Set.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Set', () => {
5151
});
5252

5353
it('accepts sequence of values', () => {
54-
let seq = Seq.of(1, 2, 3);
54+
let seq = Seq([1, 2, 3]);
5555
let s = Set(seq);
5656
expect(s.has(1)).toBe(true);
5757
expect(s.has(2)).toBe(true);
@@ -89,15 +89,15 @@ describe('Set', () => {
8989
});
9090

9191
it('accepts explicit values', () => {
92-
let s = Set.of(1, 2, 3);
92+
let s = Set([1, 2, 3]);
9393
expect(s.has(1)).toBe(true);
9494
expect(s.has(2)).toBe(true);
9595
expect(s.has(3)).toBe(true);
9696
expect(s.has(4)).toBe(false);
9797
});
9898

9999
it('converts back to JS array', () => {
100-
let s = Set.of(1, 2, 3);
100+
let s = Set([1, 2, 3]);
101101
expect(s.toArray()).toEqual([1, 2, 3]);
102102
});
103103

@@ -123,7 +123,7 @@ describe('Set', () => {
123123
});
124124

125125
it('iterates values', () => {
126-
let s = Set.of(1, 2, 3);
126+
let s = Set([1, 2, 3]);
127127
let iterator = jest.genMockFunction();
128128
s.forEach(iterator);
129129
expect(iterator.mock.calls).toEqual([

__tests__/concat.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jasmine.addMatchers({
2626
describe('concat', () => {
2727

2828
it('concats two sequences', () => {
29-
let a = Seq.of(1, 2, 3);
30-
let b = Seq.of(4, 5, 6);
31-
expect(a.concat(b)).is(Seq.of(1, 2, 3, 4, 5, 6));
29+
let a = Seq([1, 2, 3]);
30+
let b = Seq([4, 5, 6]);
31+
expect(a.concat(b)).is(Seq([1, 2, 3, 4, 5, 6]));
3232
expect(a.concat(b).size).toBe(6);
3333
expect(a.concat(b).toArray()).toEqual([1, 2, 3, 4, 5, 6]);
3434
});
@@ -56,20 +56,20 @@ describe('concat', () => {
5656
});
5757

5858
it('concats arrays to indexed seq', () => {
59-
let a = Seq.of(1, 2, 3);
59+
let a = Seq([1, 2, 3]);
6060
let b = [4, 5, 6];
6161
expect(a.concat(b).size).toBe(6);
6262
expect(a.concat(b).toArray()).toEqual([1, 2, 3, 4, 5, 6]);
6363
});
6464

6565
it('concats values', () => {
66-
let a = Seq.of(1, 2, 3);
66+
let a = Seq([1, 2, 3]);
6767
expect(a.concat(4, 5, 6).size).toBe(6);
6868
expect(a.concat(4, 5, 6).toArray()).toEqual([1, 2, 3, 4, 5, 6]);
6969
});
7070

7171
it('doesnt concat objects to indexed seq', () => {
72-
let a = Seq.of(0, 1, 2, 3);
72+
let a = Seq([0, 1, 2, 3]);
7373
let b = {4: 4};
7474
let i = a.concat(b);
7575
expect(i.size).toBe(5);
@@ -78,41 +78,41 @@ describe('concat', () => {
7878
});
7979

8080
it('concats multiple arguments', () => {
81-
let a = Seq.of(1, 2, 3);
81+
let a = Seq([1, 2, 3]);
8282
let b = [4, 5, 6];
8383
let c = [7, 8, 9];
8484
expect(a.concat(b, c).size).toBe(9);
8585
expect(a.concat(b, c).toArray()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
8686
});
8787

8888
it('can concat itself!', () => {
89-
let a = Seq.of(1, 2, 3);
89+
let a = Seq([1, 2, 3]);
9090
expect(a.concat(a, a).size).toBe(9);
9191
expect(a.concat(a, a).toArray()).toEqual([1, 2, 3, 1, 2, 3, 1, 2, 3]);
9292
});
9393

9494
it('returns itself when concat does nothing', () => {
95-
let a = Seq.of(1, 2, 3);
95+
let a = Seq([1, 2, 3]);
9696
let b = Seq();
9797
expect(a.concat()).toBe(a);
9898
expect(a.concat(b)).toBe(a);
9999
expect(b.concat(b)).toBe(b);
100100
});
101101

102102
it('returns non-empty item when concat does nothing', () => {
103-
let a = Seq.of(1, 2, 3);
103+
let a = Seq([1, 2, 3]);
104104
let b = Seq();
105105
expect(a.concat(b)).toBe(a);
106106
expect(b.concat(a)).toBe(a);
107107
expect(b.concat(b, b, b, a, b, b)).toBe(a);
108108
});
109109

110110
it('always returns the same type', () => {
111-
let a = Set.of(1, 2, 3);
111+
let a = Set([1, 2, 3]);
112112
let b = List();
113113
expect(b.concat(a)).not.toBe(a);
114114
expect(List.isList(b.concat(a))).toBe(true);
115-
expect(b.concat(a)).is(List.of(1, 2, 3));
115+
expect(b.concat(a)).is(List([1, 2, 3]));
116116
});
117117

118118
it('iterates repeated keys', () => {

__tests__/count.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { Range, Seq } from '../';
55
describe('count', () => {
66

77
it('counts sequences with known lengths', () => {
8-
expect(Seq.of(1, 2, 3, 4, 5).size).toBe(5);
9-
expect(Seq.of(1, 2, 3, 4, 5).count()).toBe(5);
8+
expect(Seq([1, 2, 3, 4, 5]).size).toBe(5);
9+
expect(Seq([1, 2, 3, 4, 5]).count()).toBe(5);
1010
});
1111

1212
it('counts sequences with unknown lengths, resulting in a cached size', () => {
13-
let seq = Seq.of(1, 2, 3, 4, 5, 6).filter(x => x % 2 === 0);
13+
let seq = Seq([1, 2, 3, 4, 5, 6]).filter(x => x % 2 === 0);
1414
expect(seq.size).toBe(undefined);
1515
expect(seq.count()).toBe(3);
1616
expect(seq.size).toBe(3);
1717
});
1818

1919
it('counts sequences with a specific predicate', () => {
20-
let seq = Seq.of(1, 2, 3, 4, 5, 6);
20+
let seq = Seq([1, 2, 3, 4, 5, 6]);
2121
expect(seq.size).toBe(6);
2222
expect(seq.count(x => x > 3)).toBe(3);
2323
});
@@ -32,15 +32,15 @@ describe('count', () => {
3232

3333
it('counts by indexed sequence', () => {
3434
expect(
35-
Seq.of(1, 2, 3, 4, 5, 6).countBy(x => x % 2).toJS(),
35+
Seq([1, 2, 3, 4, 5, 6]).countBy(x => x % 2).toJS(),
3636
).toEqual(
3737
{1: 3, 0: 3},
3838
);
3939
});
4040

4141
it('counts by specific keys', () => {
4242
expect(
43-
Seq.of(1, 2, 3, 4, 5, 6).countBy(x => x % 2 ? 'odd' : 'even').toJS(),
43+
Seq([1, 2, 3, 4, 5, 6]).countBy(x => x % 2 ? 'odd' : 'even').toJS(),
4444
).toEqual(
4545
{odd: 3, even: 3},
4646
);
@@ -51,19 +51,19 @@ describe('count', () => {
5151
describe('isEmpty', () => {
5252

5353
it('is O(1) on sequences with known lengths', () => {
54-
expect(Seq.of(1, 2, 3, 4, 5).size).toBe(5);
55-
expect(Seq.of(1, 2, 3, 4, 5).isEmpty()).toBe(false);
54+
expect(Seq([1, 2, 3, 4, 5]).size).toBe(5);
55+
expect(Seq([1, 2, 3, 4, 5]).isEmpty()).toBe(false);
5656
expect(Seq().size).toBe(0);
5757
expect(Seq().isEmpty()).toBe(true);
5858
});
5959

6060
it('lazily evaluates Seq with unknown length', () => {
61-
let seq = Seq.of(1, 2, 3, 4, 5, 6).filter(x => x % 2 === 0);
61+
let seq = Seq([1, 2, 3, 4, 5, 6]).filter(x => x % 2 === 0);
6262
expect(seq.size).toBe(undefined);
6363
expect(seq.isEmpty()).toBe(false);
6464
expect(seq.size).toBe(undefined);
6565

66-
seq = Seq.of(1, 2, 3, 4, 5, 6).filter(x => x > 10);
66+
seq = Seq([1, 2, 3, 4, 5, 6]).filter(x => x > 10);
6767
expect(seq.size).toBe(undefined);
6868
expect(seq.isEmpty()).toBe(true);
6969
expect(seq.size).toBe(undefined);

__tests__/find.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import { List, Range, Seq } from '../';
88
describe('find', () => {
99

1010
it('find returns notSetValue when match is not found', () => {
11-
expect(Seq.of(1, 2, 3, 4, 5, 6).find(function () {
11+
expect(Seq([1, 2, 3, 4, 5, 6]).find(function () {
1212
return false;
1313
}, null, 9)).toEqual(9);
1414
});
1515

1616
it('findEntry returns notSetValue when match is not found', () => {
17-
expect(Seq.of(1, 2, 3, 4, 5, 6).findEntry(function () {
17+
expect(Seq([1, 2, 3, 4, 5, 6]).findEntry(function () {
1818
return false;
1919
}, null, 9)).toEqual(9);
2020
});
2121

2222
it('findLastEntry returns notSetValue when match is not found', () => {
23-
expect(Seq.of(1, 2, 3, 4, 5, 6).findLastEntry(function () {
23+
expect(Seq([1, 2, 3, 4, 5, 6]).findLastEntry(function () {
2424
return false;
2525
}, null, 9)).toEqual(9);
2626
});

__tests__/flatten.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ describe('flatten', () => {
2828
type SeqType = number | Array<number> | Collection<number, number>;
2929

3030
it('flattens only Sequences (not sequenceables)', () => {
31-
let nested = Seq.of<SeqType>(Range(1, 3), [3, 4], List.of(5, 6, 7), 8);
31+
let nested = Seq<SeqType>([Range(1, 3), [3, 4], List([5, 6, 7]), 8]);
3232
let flat = nested.flatten();
3333
expect(flat.toJS()).toEqual([1, 2, [3, 4], 5, 6, 7, 8]);
3434
});
3535

3636
it('can be reversed', () => {
37-
let nested = Seq.of<SeqType>(Range(1, 3), [3, 4], List.of(5, 6, 7), 8);
37+
let nested = Seq<SeqType>([Range(1, 3), [3, 4], List([5, 6, 7]), 8]);
3838
let flat = nested.flatten();
3939
let reversed = flat.reverse();
4040
expect(reversed.toJS()).toEqual([8, 7, 6, 5, [3, 4], 2, 1]);

__tests__/groupBy.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,43 @@ describe('groupBy', () => {
1515

1616
it('groups indexed sequence', () => {
1717
expect(
18-
Seq.of(1, 2, 3, 4, 5, 6).groupBy(x => x % 2).toJS(),
18+
Seq([1, 2, 3, 4, 5, 6]).groupBy(x => x % 2).toJS(),
1919
).toEqual(
2020
{1: [1, 3, 5], 0: [2, 4, 6]},
2121
);
2222
});
2323

2424
it('groups to keys', () => {
2525
expect(
26-
Seq.of(1, 2, 3, 4, 5, 6).groupBy(x => x % 2 ? 'odd' : 'even').toJS(),
26+
Seq([1, 2, 3, 4, 5, 6]).groupBy(x => x % 2 ? 'odd' : 'even').toJS(),
2727
).toEqual(
2828
{odd: [1, 3, 5], even: [2, 4, 6]},
2929
);
3030
});
3131

3232
it('groups indexed sequences, maintaining indicies when keyed sequences', () => {
3333
expect(
34-
Seq.of(1, 2, 3, 4, 5, 6).groupBy(x => x % 2).toJS(),
34+
Seq([1, 2, 3, 4, 5, 6]).groupBy(x => x % 2).toJS(),
3535
).toEqual(
3636
{1: [1, 3, 5], 0: [2, 4, 6]},
3737
);
3838
expect(
39-
Seq.of(1, 2, 3, 4, 5, 6).toKeyedSeq().groupBy(x => x % 2).toJS(),
39+
Seq([1, 2, 3, 4, 5, 6]).toKeyedSeq().groupBy(x => x % 2).toJS(),
4040
).toEqual(
4141
{1: {0: 1, 2: 3, 4: 5}, 0: {1: 2, 3: 4, 5: 6}},
4242
);
4343
});
4444

4545
it('has groups that can be mapped', () => {
4646
expect(
47-
Seq.of(1, 2, 3, 4, 5, 6).groupBy(x => x % 2).map(group => group.map(value => value * 10)).toJS(),
47+
Seq([1, 2, 3, 4, 5, 6]).groupBy(x => x % 2).map(group => group.map(value => value * 10)).toJS(),
4848
).toEqual(
4949
{1: [10, 30, 50], 0: [20, 40, 60]},
5050
);
5151
});
5252

5353
it('returns an ordered map from an ordered collection', () => {
54-
let seq = Seq.of('Z', 'Y', 'X', 'Z', 'Y', 'X');
54+
let seq = Seq(['Z', 'Y', 'X', 'Z', 'Y', 'X']);
5555
expect(Collection.isOrdered(seq)).toBe(true);
5656
let seqGroups = seq.groupBy(x => x);
5757
expect(Collection.isOrdered(seqGroups)).toBe(true);

__tests__/join.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { Seq } from '../';
88
describe('join', () => {
99

1010
it('string-joins sequences with commas by default', () => {
11-
expect(Seq.of(1, 2, 3, 4, 5).join()).toBe('1,2,3,4,5');
11+
expect(Seq([1, 2, 3, 4, 5]).join()).toBe('1,2,3,4,5');
1212
});
1313

1414
it('string-joins sequences with any string', () => {
15-
expect(Seq.of(1, 2, 3, 4, 5).join('foo')).toBe('1foo2foo3foo4foo5');
15+
expect(Seq([1, 2, 3, 4, 5]).join('foo')).toBe('1foo2foo3foo4foo5');
1616
});
1717

1818
it('string-joins sequences with empty string', () => {
19-
expect(Seq.of(1, 2, 3, 4, 5).join('')).toBe('12345');
19+
expect(Seq([1, 2, 3, 4, 5]).join('')).toBe('12345');
2020
});
2121

2222
it('joins sparse-sequences like Array.join', () => {

__tests__/minmax.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ describe('max', () => {
4242

4343
it('surfaces NaN, null, and undefined', () => {
4444
expect(
45-
is(NaN, Seq.of(1, 2, 3, 4, 5, NaN).max()),
45+
is(NaN, Seq([1, 2, 3, 4, 5, NaN]).max()),
4646
).toBe(true);
4747
expect(
48-
is(NaN, Seq.of(NaN, 1, 2, 3, 4, 5).max()),
48+
is(NaN, Seq([NaN, 1, 2, 3, 4, 5]).max()),
4949
).toBe(true);
5050
expect(
51-
is(null, Seq.of('A', 'B', 'C', 'D', null).max()),
51+
is(null, Seq(['A', 'B', 'C', 'D', null]).max()),
5252
).toBe(true);
5353
expect(
54-
is(null, Seq.of(null, 'A', 'B', 'C', 'D').max()),
54+
is(null, Seq([null, 'A', 'B', 'C', 'D']).max()),
5555
).toBe(true);
5656
});
5757

5858
it('null treated as 0 in default iterator', () => {
5959
expect(
60-
is(2, Seq.of(-1, -2, null, 1, 2).max()),
60+
is(2, Seq([-1, -2, null, 1, 2]).max()),
6161
).toBe(true);
6262
});
6363

0 commit comments

Comments
 (0)