Skip to content

Commit

Permalink
style: misc formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Apr 3, 2024
1 parent 6d6e473 commit 77f8535
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 73 deletions.
2 changes: 0 additions & 2 deletions src/operations/cache.js
Expand Up @@ -31,7 +31,6 @@ export const cache = iterable => {
}

const { value, done } = iterator.next()

if (done) {
break
}
Expand All @@ -57,7 +56,6 @@ export const cacheAsync = asyncIterable => {
}

const { value, done } = await asyncIterator.next()

if (done) {
break
}
Expand Down
2 changes: 0 additions & 2 deletions src/operations/collect.js
Expand Up @@ -81,7 +81,6 @@ export const toGrouped = curry((innerReducer, outerReducer) => {
create: () => ({ _acc: createOuter(), _keys: [] }),
add: (acc, [key, value]) => {
let group = getOuter(acc._acc, key)

if (group === NO_ENTRY) {
group = createInner ? addInner(createInner(), value) : value
acc._keys.push(key)
Expand Down Expand Up @@ -127,7 +126,6 @@ export const toMultiple = reducers => {
const add = (acc, value) =>
applyReducers(acc, (acc, { add }) => add(acc, value))
const finish = acc => applyReducers(acc, (acc, { finish }) => finish(acc))

if (reducers.every(([, { create }]) => create)) {
return {
create: () => mapReducers(({ create }) => create()),
Expand Down
3 changes: 0 additions & 3 deletions src/operations/exclude.js
Expand Up @@ -64,7 +64,6 @@ export const uniqueBy = curry((fn, iterable) =>

for (const value of iterable) {
const by = fn(value)

if (set.has(by)) {
continue
}
Expand All @@ -81,7 +80,6 @@ export const uniqueByAsync = curry((fn, asyncIterable) =>

for await (const value of asyncIterable) {
const by = await fn(value)

if (set.has(by)) {
continue
}
Expand All @@ -97,7 +95,6 @@ export const uniqueByConcur = curry((fn, concurIterable) => apply => {

return concurIterable(async value => {
const by = await fn(value)

if (set.has(by)) {
return
}
Expand Down
6 changes: 2 additions & 4 deletions src/operations/generate.js
Expand Up @@ -53,9 +53,8 @@ export const cycle = iterable => {
return createIterable(function* () {
const iterator = iterable[Symbol.iterator]()
const { value, done } = iterator.next()

// This is an empty iterable! Return early to avoid an infinite loop
if (done) {
// This is an empty iterable! Return early to avoid an infinite loop.
return
}

Expand All @@ -76,9 +75,8 @@ export const cycleAsync = asyncIterable => {
return createAsyncIterable(async function* () {
const asyncIterator = asyncIterable[Symbol.asyncIterator]()
const { value, done } = await asyncIterator.next()

// This is an empty iterable! Return early to avoid an infinite loop
if (done) {
// This is an empty iterable! Return early to avoid an infinite loop.
return
}

Expand Down
3 changes: 0 additions & 3 deletions src/operations/reduce.js
Expand Up @@ -23,7 +23,6 @@ import { map } from './transform.js'

export const reduce = curry((reducer, iterable) => {
const { create, add, finish } = normalizeReducer(reducer)

if (create) {
return reduceInternal(create(), add, finish, iterable)
}
Expand All @@ -45,7 +44,6 @@ const reduceInternal = (acc, add, finish, iterable) => {
export const reduceAsync = curry((asyncReducer, asyncIterable) => {
const { create, add, combine, finish } = normalizeReducer(asyncReducer)
const concurIterable = asConcur(asyncIterable)

if (!create) {
return createAsyncIterable(async function* () {
yield* await reduceConcurWithoutCreate(add, finish, concurIterable)
Expand All @@ -70,7 +68,6 @@ export const reduceAsync = curry((asyncReducer, asyncIterable) => {

export const reduceConcur = curry((asyncReducer, concurIterable) => {
const { create, add, combine, finish } = normalizeReducer(asyncReducer)

if (!create) {
return async apply => {
const accs = await reduceConcurWithoutCreate(add, finish, concurIterable)
Expand Down
2 changes: 0 additions & 2 deletions src/operations/reducer.js
Expand Up @@ -29,15 +29,13 @@ export const mapAsyncReducer = curry((fn, asyncReducer) => {

export const normalizeReducer = reducer => {
const normalizedReducer = { finish: identity }

if (typeof reducer === `function`) {
normalizedReducer.add = reducer
return normalizedReducer
}

for (const methodName of REDUCER_METHOD_NAMES) {
const method = reducer[methodName]

if (method) {
normalizedReducer[methodName] = method.bind(reducer)
}
Expand Down
3 changes: 0 additions & 3 deletions src/operations/slice.js
Expand Up @@ -150,7 +150,6 @@ export const chunk = curry((size, iterable) => {
let chunk = []
for (const value of iterable) {
chunk.push(value)

if (chunk.length < size) {
continue
}
Expand All @@ -172,7 +171,6 @@ export const chunkAsync = curry((size, asyncIterable) => {
let chunk = []
for await (const value of asyncIterable) {
chunk.push(value)

if (chunk.length < size) {
continue
}
Expand All @@ -194,7 +192,6 @@ export const chunkConcur = curry((size, concurIterable) => {
let chunk = []
await concurIterable(async value => {
chunk.push(value)

if (chunk.length < size) {
return
}
Expand Down
2 changes: 0 additions & 2 deletions src/operations/statistics.js
Expand Up @@ -54,7 +54,6 @@ export const toMaxBy = fn =>
export const toMinMaxBy = fn =>
mapReducer(ensureMinMax, (acc, value) => {
const minMax = asMinMax(acc)

if (fn(value, minMax._min) < 0) {
minMax._min = value
} else if (fn(value, minMax._max) > 0) {
Expand All @@ -77,7 +76,6 @@ export const toMinMaxByAsync = fn => {

return mapAsyncReducer(ensureMinMax, async (acc, value) => {
const minMax = asMinMax(acc)

if (minMaxSet.has(value)) {
;[minMax._min, minMax._max] = await Promise.all([
addMin(value._min, minMax._min),
Expand Down
1 change: 0 additions & 1 deletion test/helpers/fast-check/fn.ts
Expand Up @@ -26,7 +26,6 @@ const getAsyncFn = <Args extends unknown[], Value>(
const asyncFn = Object.assign(
(...args: Args) => {
const [value, shouldReturnPromise] = fn(...args)

if (!shouldReturnPromise) {
return value
}
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/fast-check/iterable.ts
Expand Up @@ -47,7 +47,7 @@ export type GeneratedIterable<Value> = {
values: Value[]
}

// Used to ensure we call `Symbol.iterator` with the right `this`
// Used to ensure we call `Symbol.iterator` with the right `this`.
class IterableWithPrivateFields<Value> {
readonly #values
readonly #index
Expand Down Expand Up @@ -85,7 +85,7 @@ export type GeneratedAsyncIterable<Value> = {
values: Value[]
}

// Used to ensure we call `Symbol.asyncIterator` with the right `this`
// Used to ensure we call `Symbol.asyncIterator` with the right `this`.
class AsyncIterableWithPrivateFields<Value> {
readonly #values
readonly #index
Expand Down
10 changes: 5 additions & 5 deletions test/helpers/fast-check/reducer.ts
Expand Up @@ -107,7 +107,7 @@ export type GeneratedRawAsyncOptionalReducerWithoutFinish<Value = unknown> = {
export const rawAsyncOptionalReducerWithoutFinishArb =
getRawAsyncOptionalReducerWithoutFinishArb(asyncFnArb)

// Used to ensure we call methods with the right `this`
// Used to ensure we call methods with the right `this`.
class RawOptionalReducerWithoutFinishWithPrivateFields<Value = unknown> {
readonly #add: Fn<Value>

Expand Down Expand Up @@ -139,7 +139,7 @@ export type GeneratedRawAsyncOptionalReducerWithFinish<Value = unknown> = {
syncReducer: RawOptionalReducerWithFinish<Value, Value>
}

// Used to ensure we call methods with the right `this`
// Used to ensure we call methods with the right `this`.
class RawOptionalReducerWithFinishAndPrivateFields<
Value = unknown,
> extends RawOptionalReducerWithoutFinishWithPrivateFields<Value> {
Expand Down Expand Up @@ -177,7 +177,7 @@ export type GeneratedRawAsyncReducerWithoutFinish<Value = unknown> = {
syncReducer: RawReducerWithoutFinish<Value, Value>
}

// Used to ensure we call methods with the right `this`
// Used to ensure we call methods with the right `this`.
class RawReducerWithoutFinishWithPrivateFields<
Value = unknown,
> extends RawOptionalReducerWithoutFinishWithPrivateFields<Value> {
Expand Down Expand Up @@ -217,7 +217,7 @@ export type GeneratedRawAsyncReducerWithFinish<Value = unknown> = {
syncReducer: RawReducerWithFinish<Value, Value, Value>
}

// Used to ensure we call methods with the right `this`
// Used to ensure we call methods with the right `this`.
class RawReducerWithFinishAndPrivateFields<
Value = unknown,
> extends RawOptionalReducerWithFinishAndPrivateFields<Value> {
Expand All @@ -233,7 +233,7 @@ class RawReducerWithFinishAndPrivateFields<
}
}

// Used to ensure we call methods with the right `this`
// Used to ensure we call methods with the right `this`.
class RawKeyedReducerWithPrivateFields extends RawReducerWithoutFinishWithPrivateFields {
readonly #get: Fn

Expand Down
16 changes: 8 additions & 8 deletions test/operations/collect.ts
Expand Up @@ -94,7 +94,7 @@ test.skip(`toWeakSet types are correct`, () => {
),
).toMatchTypeOf<WeakSet<{ n: number }>>()

// @ts-expect-error WeakSets can't contain primitives
// @ts-expect-error WeakSets can't contain primitives.
toWeakSet<string>()
})

Expand Down Expand Up @@ -129,7 +129,7 @@ test.skip(`toObject types are correct`, () => {
),
).toMatchTypeOf<Record<string, number>>()

// @ts-expect-error Objects can only have string, symbol, and number keys
// @ts-expect-error Objects can only have string, symbol, and number keys.
toObject<object, string>()
})

Expand Down Expand Up @@ -158,7 +158,7 @@ test.skip(`toWeakMap types are correct`, () => {
),
).toMatchTypeOf<WeakMap<{ n: number }, number>>()

// @ts-expect-error WeakMaps can't have primitive keys
// @ts-expect-error WeakMaps can't have primitive keys.
toWeakMap<string, string>()
})

Expand Down Expand Up @@ -257,7 +257,7 @@ test.skip(`toGrouped types are correct`, () => {
),
).toMatchTypeOf<Map<number, number>>()

// @ts-expect-error TODO: Make this typecheck without generic type arguments
// @ts-expect-error TODO: Make this typecheck without generic type arguments.
toGrouped((a: number, b: number) => a + b, toMap())

expectTypeOf(
Expand Down Expand Up @@ -451,14 +451,14 @@ test.skip(`toMultiple types are correct`, () => {
pipe([1, 2, 3], reduce(toMultiple([toMax(), toSet()])), get),
).toMatchTypeOf<[number, Set<number>]>()

// @ts-expect-error TODO: Make this typecheck without generic type arguments
// @ts-expect-error TODO: Make this typecheck without generic type arguments.
toMultiple([toMax(), toSet()])

expectTypeOf(
pipe([1, 2, 3], reduce(toMultiple({ max: toMax(), set: toSet() })), get),
).toMatchTypeOf<{ max: number; set: Set<number> }>()

// @ts-expect-error TODO: Make this typecheck without generic type arguments
// @ts-expect-error TODO: Make this typecheck without generic type arguments.
toMultiple({ max: toMax(), set: toSet() })

expectTypeOf(
Expand Down Expand Up @@ -672,12 +672,12 @@ testProp(
for (const value of values) {
expect(joined).toContain(String(value))
}
// Max.max is needed in case the iterable is empty
// Max.max is needed in case the iterable is empty.
const expectedSeparatorCount =
separator === `` ? 0 : Math.max(values.length - 1, 0)
// The number of occurrences of the separator exceeds the "expected" count
// when a string representation of a value in the iterable contains the
// separator
// separator.
expect(count(indicesOf(joined, separator))).toBeGreaterThanOrEqual(
expectedSeparatorCount,
)
Expand Down
12 changes: 6 additions & 6 deletions test/operations/generate.ts
Expand Up @@ -255,13 +255,13 @@ test.skip(`rangeUntil types are correct`, () => {
expectTypeOf(rangeUntil(0, 5)).toMatchTypeOf<Iterable<number>>()
expectTypeOf(rangeUntil(0, 5).step(2)).toMatchTypeOf<Iterable<number>>()

// @ts-expect-error Non-integer literals
// @ts-expect-error Non-integer literals.
rangeUntil(0.2, 5)

// @ts-expect-error Non-integer literals
// @ts-expect-error Non-integer literals.
rangeUntil(0.2, 5.2)

// @ts-expect-error A non-integer literal
// @ts-expect-error A non-integer literal.
rangeUntil(0, 5.2)

const decimal = 2.4 as number
Expand Down Expand Up @@ -396,13 +396,13 @@ test.skip(`rangeTo types are correct`, () => {
expectTypeOf(rangeTo(0, 5)).toMatchTypeOf<Iterable<number>>()
expectTypeOf(rangeTo(0, 5).step(2)).toMatchTypeOf<Iterable<number>>()

// @ts-expect-error Non-integer literals
// @ts-expect-error Non-integer literals.
rangeTo(0.2, 5)

// @ts-expect-error Non-integer literals
// @ts-expect-error Non-integer literals.
rangeTo(0.2, 5.2)

// @ts-expect-error A non-integer literal
// @ts-expect-error A non-integer literal.
rangeTo(0, 5.2)

const decimal = 2.4 as number
Expand Down

0 comments on commit 77f8535

Please sign in to comment.