-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f75a25
commit 8e66ca7
Showing
1 changed file
with
2 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |