1 /*! *****************************************************************************
2 Copyright (c) Microsoft Corporation. All rights reserved.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the
5 License at http://www.apache.org/licenses/LICENSE-2.0
7 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 MERCHANTABLITY OR NON-INFRINGEMENT.
12 See the Apache Version 2.0 License for specific language governing permissions
13 and limitations under the License.
14 ***************************************************************************** */
18 /// <reference no-default-lib="true"/>
\r
21 type FlatArray<Arr, Depth extends number> = {
\r
23 "recur": Arr extends ReadonlyArray<infer InnerArr>
\r
24 ? FlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]>
\r
26 }[Depth extends -1 ? "done" : "recur"];
\r
28 interface ReadonlyArray<T> {
\r
31 * Calls a defined callback function on each element of an array. Then, flattens the result into
\r
33 * This is identical to a map followed by flat with depth 1.
\r
35 * @param callback A function that accepts up to three arguments. The flatMap method calls the
\r
36 * callback function one time for each element in the array.
\r
37 * @param thisArg An object to which the this keyword can refer in the callback function. If
\r
38 * thisArg is omitted, undefined is used as the this value.
\r
40 flatMap<U, This = undefined> (
\r
41 callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
\r
47 * Returns a new array with all sub-array elements concatenated into it recursively up to the
\r
50 * @param depth The maximum recursion depth
\r
52 flat<A, D extends number = 1>(
\r
55 ): FlatArray<A, D>[]
\r
58 interface Array<T> {
\r
61 * Calls a defined callback function on each element of an array. Then, flattens the result into
\r
63 * This is identical to a map followed by flat with depth 1.
\r
65 * @param callback A function that accepts up to three arguments. The flatMap method calls the
\r
66 * callback function one time for each element in the array.
\r
67 * @param thisArg An object to which the this keyword can refer in the callback function. If
\r
68 * thisArg is omitted, undefined is used as the this value.
\r
70 flatMap<U, This = undefined> (
\r
71 callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
\r
76 * Returns a new array with all sub-array elements concatenated into it recursively up to the
\r
79 * @param depth The maximum recursion depth
\r
81 flat<A, D extends number = 1>(
\r
84 ): FlatArray<A, D>[]
\r