Skip to content

Commit 8e66ca7

Browse files
committed
simplify toLength
1 parent 2f75a25 commit 8e66ca7

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/toLength.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
import { isAsyncIterable } from './utils/iterator'
2-
import { pipe } from './pipe'
3-
import { toArray } from './toArray'
4-
import { LazyIterable } from './shared-types'
1+
import { reduce } from './reduce'
52

63
export function toLength() {
7-
return function toLengthFn(data: LazyIterable<any>) {
8-
if (isAsyncIterable(data) || data instanceof Promise) {
9-
return (async () => {
10-
let stream = data instanceof Promise ? await data : data
11-
12-
let program = pipe(toArray())
13-
let array = await program(stream)
14-
15-
return array.length
16-
})()
17-
}
18-
19-
return Array.from(data).length
20-
}
4+
return reduce((_value, acc) => acc + 1, 0)
215
}

0 commit comments

Comments
 (0)