-
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
Showing
15 changed files
with
364 additions
and
0 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
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
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
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
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
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 |
---|---|---|
|
@@ -85,3 +85,5 @@ export const binarySearchBy = <A>( | |
} | ||
} | ||
}; | ||
|
||
export { unzip, zip } from "./ZipUnzip"; |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export const unzip = <TupleArray extends [any, any][]>(array: TupleArray) => { | ||
const length = array.length; | ||
const arrayA = Array(length); | ||
const arrayB = Array(length); | ||
let index = -1; | ||
while (++index < length) { | ||
const match = array[index]; | ||
if (match !== undefined) { | ||
arrayA[index] = match[0]; | ||
arrayB[index] = match[1]; | ||
} | ||
} | ||
return [arrayA, arrayB] as unknown as [ | ||
{ | ||
[I in keyof TupleArray]: TupleArray[I] extends [any, any] | ||
? TupleArray[I][0] extends infer T | ||
? T | ||
: never | ||
: never; | ||
}, | ||
{ | ||
[I in keyof TupleArray]: TupleArray[I] extends [any, any] | ||
? TupleArray[I][1] extends infer T | ||
? T | ||
: never | ||
: never; | ||
}, | ||
]; | ||
}; | ||
|
||
export const zip = <ArrayA extends any[], ArrayB extends any[]>( | ||
arrayA: ArrayA, | ||
arrayB: ArrayB, | ||
) => { | ||
const length = Math.min(arrayA.length, arrayB.length); | ||
const array = Array(length); | ||
let index = -1; | ||
while (++index < length) { | ||
array[index] = [arrayA[index], arrayB[index]]; | ||
} | ||
return array as unknown as Array< | ||
[ | ||
{ | ||
[I in keyof ArrayA]: ArrayA[I] extends infer T ? T : never; | ||
}[number], | ||
{ | ||
[I in keyof ArrayB]: ArrayB[I] extends infer T ? T : never; | ||
}[number], | ||
] | ||
>; | ||
}; |
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
Oops, something went wrong.