@@ -5,15 +5,16 @@ export interface BaseCompareOptions<TLeft, TRight> {
5
5
onMatch ?: ( left : TLeft , right : TRight ) => void ;
6
6
}
7
7
8
- export interface CompareListsOptions < TLeft , TRight > extends BaseCompareOptions < TLeft , TRight > {
8
+ export interface CompareListsOptions < TLeft , TRight >
9
+ extends BaseCompareOptions < TLeft , TRight > {
9
10
left : Iterable < TLeft > ;
10
11
right : Iterable < TRight > ;
11
12
}
12
13
13
14
export interface CompareListsReport < TLeft , TRight > {
14
15
missingInLeft : TRight [ ] ;
15
16
missingInRight : TLeft [ ] ;
16
- matches : Array < [ TLeft , TRight ] > ;
17
+ matches : [ TLeft , TRight ] [ ] ;
17
18
}
18
19
19
20
export function compareLists < TLeft , TRight > (
@@ -33,7 +34,13 @@ export function compareLists<TLeft, TRight>(
33
34
const leftIterator = options . left [ Symbol . iterator ] ( ) ;
34
35
const rightIterator = options . right [ Symbol . iterator ] ( ) ;
35
36
36
- const { compare, returnReport, onMissingInLeft, onMissingInRight, onMatch } = options ;
37
+ const {
38
+ compare,
39
+ returnReport,
40
+ onMissingInLeft,
41
+ onMissingInRight,
42
+ onMatch
43
+ } = options ;
37
44
38
45
const result = compareIterators ( {
39
46
left : leftIterator ,
@@ -48,7 +55,8 @@ export function compareLists<TLeft, TRight>(
48
55
return result ;
49
56
}
50
57
51
- export interface CompareIteratorsOptions < TLeft , TRight > extends BaseCompareOptions < TLeft , TRight > {
58
+ export interface CompareIteratorsOptions < TLeft , TRight >
59
+ extends BaseCompareOptions < TLeft , TRight > {
52
60
left : Iterator < TLeft > ;
53
61
right : Iterator < TRight > ;
54
62
}
@@ -69,23 +77,27 @@ export function compareIterators<TLeft, TRight>(
69
77
) : void | CompareListsReport < TLeft , TRight > {
70
78
const leftIterator = options . left ;
71
79
const rightIterator = options . right ;
72
- const { compare, onMissingInLeft, onMissingInRight, onMatch, returnReport } = options ;
80
+ const {
81
+ compare,
82
+ onMissingInLeft,
83
+ onMissingInRight,
84
+ onMatch,
85
+ returnReport
86
+ } = options ;
73
87
74
- const result = (
75
- returnReport ?
76
- {
88
+ const result = returnReport
89
+ ? ( {
77
90
missingInLeft : [ ] ,
78
91
missingInRight : [ ] ,
79
92
matches : [ ]
80
- } as CompareListsReport < TLeft , TRight > :
81
- undefined
82
- ) ;
93
+ } as CompareListsReport < TLeft , TRight > )
94
+ : undefined ;
83
95
84
96
let left : IteratorResult < TLeft > ;
85
97
let right : IteratorResult < TRight > ;
86
98
87
- const nextLeft = ( ) => left = leftIterator . next ( ) ;
88
- const nextRight = ( ) => right = rightIterator . next ( ) ;
99
+ const nextLeft = ( ) => ( left = leftIterator . next ( ) ) ;
100
+ const nextRight = ( ) => ( right = rightIterator . next ( ) ) ;
89
101
90
102
const handleMissingInLeft = ( ) => {
91
103
if ( returnReport ) {
@@ -122,10 +134,11 @@ export function compareIterators<TLeft, TRight>(
122
134
nextRight ( ) ;
123
135
124
136
while ( ! left . done || ! right . done ) {
125
- const compareResult =
126
- left . done ? 1 :
127
- right . done ? - 1 :
128
- compare ( left . value , right . value ) ;
137
+ const compareResult = left . done
138
+ ? 1
139
+ : right . done
140
+ ? - 1
141
+ : compare ( left . value , right . value ) ;
129
142
130
143
if ( compareResult < 0 ) {
131
144
handleMissingInRight ( ) ;
0 commit comments