-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
03b2de6
commit 287eb96
Showing
7 changed files
with
53 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export type DeepArray<T> = Array<T | ReadonlyDeepArray<T>>; | ||
|
||
// Just to make sure that DeepArray<T> is not assignable to ReadonlyDeepArray<T> | ||
declare const __marker: unique symbol; | ||
export type ReadonlyDeepArray<T> = ReadonlyArray<T | ReadonlyDeepArray<T>> & { | ||
[__marker]: true; | ||
}; | ||
|
||
export function finalize<T>(deepArr: DeepArray<T>): ReadonlyDeepArray<T> { | ||
return Object.freeze(deepArr) as ReadonlyDeepArray<T>; | ||
} | ||
|
||
export function flattenToSet<T>(arr: ReadonlyDeepArray<T>): Set<T> { | ||
const result = new Set<T>(); | ||
const stack = [arr]; | ||
while (stack.length > 0) { | ||
for (const el of stack.pop()) { | ||
if (Array.isArray(el)) stack.push(el as ReadonlyDeepArray<T>); | ||
else result.add(el as T); | ||
} | ||
} | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
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