Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Use Array.from({ length }) to create array from length
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Aug 23, 2019
1 parent 6d247d1 commit 0f759f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions codegen/gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function typeParams (quantity: number) {
return Array(quantity)
.fill(null)
return Array
.from({ length: quantity })
.map((_, i) => ' T' + i)
.join(',\n')
}
Expand All @@ -9,8 +9,8 @@ function pipeValParams (quantity: number) {
const sig = (arg: number, res: number) =>
`(x: T${arg}) => T${res}`

const params = Array(quantity - 1)
.fill(null)
const params = Array
.from({ length: quantity - 1 })
.map((_, i) => ` f${i + 1}: ${sig(i, i + 1)}`)
.join(',\n')

Expand All @@ -21,8 +21,8 @@ function composeValParams (quantity: number) {
const sig = (arg: number, res: number) =>
`(x: T${arg}) => T${res}`

const begin = Array(quantity - 1)
.fill(null)
const begin = Array
.from({ length: quantity - 1 })
.map((_, i) => ` f${i}: ${sig(i + 1, i)}`)
.join(',\n')

Expand All @@ -44,8 +44,8 @@ interface Gen {
}

function mkgen (fn: Gen): Gen {
return (quantity, name) => Array(quantity)
.fill(null)
return (quantity, name) => Array
.from({ length: quantity })
.map((_, i) => fn(i + 1, name))
.join('\n')
}
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('pipeline', () => {
const x0 = Symbol('x0')
const f0 = jest.fn((..._: string[]) => x0)
const fn = pipeline(f0)
const ys = Array(times).fill(null).map(() => fn(...args))
const ys = Array.from({ length: times }).map(() => fn(...args))
return { args, x0, f0, fn, ys }
}

Expand Down Expand Up @@ -130,7 +130,7 @@ describe('pipeline', () => {
const f2 = jest.fn(() => x2)
const f3 = jest.fn(() => x3)
const fn = pipeline(f0, f1, f2, f3)
const ys = Array(times).fill(null).map(() => fn(...args))
const ys = Array.from({ length: times }).map(() => fn(...args))
return { args, x0, x1, x2, x3, f0, f1, f2, f3, fn, ys }
}

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('compose', () => {
const x0 = Symbol('x0')
const f0 = jest.fn((..._: string[]) => x0)
const fn = compose(f0)
const ys = Array(times).fill(null).map(() => fn(...args))
const ys = Array.from({ length: times }).map(() => fn(...args))
return { args, x0, f0, fn, ys }
}

Expand Down Expand Up @@ -254,7 +254,7 @@ describe('compose', () => {
const f2 = jest.fn(() => x2)
const f3 = jest.fn((..._: string[]) => x3)
const fn = compose(f0, f1, f2, f3)
const ys = Array(times).fill(null).map(() => fn(...args))
const ys = Array.from({ length: times }).map(() => fn(...args))
return { args, x0, x1, x2, x3, f0, f1, f2, f3, fn, ys }
}

Expand Down

0 comments on commit 0f759f2

Please sign in to comment.