Skip to content

Commit 9f6fc3b

Browse files
committed
Fix handling zero
1 parent c9685fa commit 9f6fc3b

15 files changed

Lines changed: 72 additions & 16 deletions

File tree

src/async/_private/firstOrDefault.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const firstOrDefault = <TSource>(
1111
const firstOrDefault1 = async <T>(source: AsyncIterable<T>) => {
1212
const first = await source[Symbol.asyncIterator]().next()
1313
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
14-
return first.value || null
14+
return first.value ?? null
1515
}
1616

1717
const firstOrDefault2 = async <T>(

src/async/_private/max.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const max: MaxFunc = <TSource>(
1818
const max1 = async (source: AsyncIterable<number>) => {
1919
let maxItem: number | null = null
2020
for await (const item of source) {
21-
maxItem = Math.max(maxItem || Number.NEGATIVE_INFINITY, item)
21+
maxItem = Math.max(maxItem ?? Number.NEGATIVE_INFINITY, item)
2222
}
2323

2424
if (maxItem === null) {
@@ -32,7 +32,7 @@ const max2 = async <TSource>(
3232
source: AsyncIterable<TSource>, selector: (x: TSource) => number) => {
3333
let maxItem: number | null = null
3434
for await (const item of source) {
35-
maxItem = Math.max(maxItem || Number.NEGATIVE_INFINITY, selector(item))
35+
maxItem = Math.max(maxItem ?? Number.NEGATIVE_INFINITY, selector(item))
3636
}
3737

3838
if (maxItem === null) {

src/async/_private/maxAsync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const maxAsync = async <TSource>(
44
source: AsyncIterable<TSource>, selector: (x: TSource) => Promise<number>): Promise<number> => {
55
let max: number | null = null
66
for await (const item of source) {
7-
max = Math.max(max || Number.NEGATIVE_INFINITY, await selector(item))
7+
max = Math.max(max ?? Number.NEGATIVE_INFINITY, await selector(item))
88
}
99

1010
if (max === null) {

src/async/_private/min.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const min: MinAsync = (source: AsyncIterable<number>, selector?: (x: numb
1616
const min1 = async (source: AsyncIterable<number>) => {
1717
let minValue: number | null = null
1818
for await (const item of source) {
19-
minValue = Math.min(minValue || Number.POSITIVE_INFINITY, item)
19+
minValue = Math.min(minValue ?? Number.POSITIVE_INFINITY, item)
2020
}
2121

2222
if (minValue === null) {
@@ -29,7 +29,7 @@ const min1 = async (source: AsyncIterable<number>) => {
2929
const min2 = async (source: AsyncIterable<number>, selector: (x: number) => number) => {
3030
let minValue: number | null = null
3131
for await (const item of source) {
32-
minValue = Math.min(minValue || Number.POSITIVE_INFINITY, selector(item))
32+
minValue = Math.min(minValue ?? Number.POSITIVE_INFINITY, selector(item))
3333
}
3434

3535
if (minValue === null) {

src/async/_private/minAsync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const minAsync = async <TSource>(
55
selector: (x: TSource) => Promise<number>): Promise<number> => {
66
let min: number | null = null
77
for await (const item of source) {
8-
min = Math.min(min || Number.POSITIVE_INFINITY, await selector(item))
8+
min = Math.min(min ?? Number.POSITIVE_INFINITY, await selector(item))
99
}
1010

1111
if (min === null) {

src/initializer/bindArrayEnumerable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const bindArrayEnumerable = <T, TKey extends keyof IEnumerable<T>>() => {
4747
return this[index] as T
4848
}
4949
prototype.elementAtOrDefault = function(index: number): T | null {
50-
return (this[index] as T | undefined) || null
50+
return (this[index] as T | undefined) ?? null
5151
}
5252
prototype.first = function(predicate?: (x: T) => boolean): T {
5353
if (predicate) {

src/sync/_private/firstOrDefault.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const firstOrDefault = <TSource>(
1010
const firstOrDefault1 = <T>(source: Iterable<T>): T | null => {
1111
const first = source[Symbol.iterator]().next()
1212
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
13-
return first.value || null
13+
return first.value ?? null
1414
}
1515

1616
const firstOrDefault2 = <T>(source: Iterable<T>, predicate: (x: T) => boolean): T | null => {

src/sync/_private/max.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const max: MaxFunc = <TSource>(
1818
const max1 = (source: Iterable<number>): number => {
1919
let maxItem: number | null = null
2020
for (const item of source) {
21-
maxItem = Math.max(maxItem || Number.NEGATIVE_INFINITY, item)
21+
maxItem = Math.max(maxItem ?? Number.NEGATIVE_INFINITY, item)
2222
}
2323

2424
if (maxItem === null) {
@@ -31,7 +31,7 @@ const max1 = (source: Iterable<number>): number => {
3131
const max2 = <TSource>(source: Iterable<TSource>, selector: (x: TSource) => number): number => {
3232
let maxItem: number | null = null
3333
for (const item of source) {
34-
maxItem = Math.max(maxItem || Number.NEGATIVE_INFINITY, selector(item))
34+
maxItem = Math.max(maxItem ?? Number.NEGATIVE_INFINITY, selector(item))
3535
}
3636

3737
if (maxItem === null) {

src/sync/_private/maxAsync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const maxAsync = async <TSource>(
44
source: Iterable<TSource>, selector: (x: TSource) => Promise<number>): Promise<number> => {
55
let max: number | null = null
66
for (const item of source) {
7-
max = Math.max(max || Number.NEGATIVE_INFINITY, await selector(item))
7+
max = Math.max(max ?? Number.NEGATIVE_INFINITY, await selector(item))
88
}
99

1010
if (max === null) {

src/sync/_private/min.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const min: MinFunc = <TSource>(source: Iterable<TSource> | Iterable<numbe
1717
const min1 = (source: Iterable<number>) => {
1818
let minItem: number | null = null
1919
for (const item of source) {
20-
minItem = Math.min(minItem || Number.POSITIVE_INFINITY, item)
20+
minItem = Math.min(minItem ?? Number.POSITIVE_INFINITY, item)
2121
}
2222

2323
if (minItem === null) {
@@ -30,7 +30,7 @@ const min1 = (source: Iterable<number>) => {
3030
const min2 = <TSource>(source: Iterable<TSource>, selector: (x: TSource) => number) => {
3131
let minItem: number | null = null
3232
for (const item of source) {
33-
minItem = Math.min(minItem || Number.POSITIVE_INFINITY, selector(item))
33+
minItem = Math.min(minItem ?? Number.POSITIVE_INFINITY, selector(item))
3434
}
3535

3636
if (minItem === null) {

0 commit comments

Comments
 (0)