Skip to content

Commit

Permalink
simplify toLength
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Sep 8, 2023
1 parent 2f75a25 commit 8e66ca7
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/toLength.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { isAsyncIterable } from './utils/iterator'
import { pipe } from './pipe'
import { toArray } from './toArray'
import { LazyIterable } from './shared-types'
import { reduce } from './reduce'

export function toLength() {
return function toLengthFn(data: LazyIterable<any>) {
if (isAsyncIterable(data) || data instanceof Promise) {
return (async () => {
let stream = data instanceof Promise ? await data : data

let program = pipe(toArray())
let array = await program(stream)

return array.length
})()
}

return Array.from(data).length
}
return reduce((_value, acc) => acc + 1, 0)
}

0 comments on commit 8e66ca7

Please sign in to comment.