Skip to content

Commit

Permalink
feat(zipalltotuple): add zipAllToTuple function
Browse files Browse the repository at this point in the history
  • Loading branch information
biggyspender committed Mar 1, 2021
1 parent 84983fb commit d1ed203
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 72 deletions.
27 changes: 27 additions & 0 deletions src/transformers/zipAllToTuple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { deferP0 } from 'ts-functional-pipe'

export function* _zipAllToTuple<T extends readonly any[]>(src: Iterablified<T>): Iterable<T> {
const iterators = (src.map((iterable) =>
iterable[Symbol.iterator]()
) as unknown) as Iteratorfied<T>
for (;;) {
const itRes = (iterators.map((it) => it.next()) as unknown) as IteratorResultified<T>
if (itRes.some((r) => r.done)) {
break
}
const v = (itRes.map((r) => r.value) as unknown) as T
yield v
}
}

export const zipAllToTuple = deferP0(_zipAllToTuple)

type Iterablified<T extends readonly any[]> = {
[P in keyof T]: Iterable<T[P]>
}
type Iteratorfied<T extends readonly any[]> = {
[P in keyof T]: Iterator<T[P]>
}
type IteratorResultified<T extends readonly any[]> = {
[P in keyof T]: IteratorResult<T[P]>
}
1 change: 1 addition & 0 deletions src/ts-iterable-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ export { unwrapIndexed, _unwrapIndexed } from './transformers/unwrapIndexed'
export { where, _where } from './transformers/where'
export { zip, _zip } from './transformers/zip'
export { zipAll, _zipAll } from './transformers/zipAll'
export { zipAllToTuple, _zipAllToTuple } from './transformers/zipAllToTuple'
Loading

0 comments on commit d1ed203

Please sign in to comment.