1/*! ***************************************************************************** 2Copyright (c) Microsoft Corporation. All rights reserved. 3Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4this file except in compliance with the License. You may obtain a copy of the 5License at http://www.apache.org/licenses/LICENSE-2.0 6 7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10MERCHANTABLITY OR NON-INFRINGEMENT. 11 12See the Apache Version 2.0 License for specific language governing permissions 13and limitations under the License. 14***************************************************************************** */ 15 16 17 18/// <reference no-default-lib="true"/> 19 20 21interface ReadonlyArray<T> { 22 23 /** 24 * Calls a defined callback function on each element of an array. Then, flattens the result into 25 * a new array. 26 * This is identical to a map followed by flat with depth 1. 27 * 28 * @param callback A function that accepts up to three arguments. The flatMap method calls the 29 * callback function one time for each element in the array. 30 * @param thisArg An object to which the this keyword can refer in the callback function. If 31 * thisArg is omitted, undefined is used as the this value. 32 */ 33 flatMap<U, This = undefined> ( 34 callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>, 35 thisArg?: This 36 ): U[] 37 38 39 /** 40 * Returns a new array with all sub-array elements concatenated into it recursively up to the 41 * specified depth. 42 * 43 * @param depth The maximum recursion depth 44 */ 45 flat<U>(this: 46 ReadonlyArray<U[][][][]> | 47 48 ReadonlyArray<ReadonlyArray<U[][][]>> | 49 ReadonlyArray<ReadonlyArray<U[][]>[]> | 50 ReadonlyArray<ReadonlyArray<U[]>[][]> | 51 ReadonlyArray<ReadonlyArray<U>[][][]> | 52 53 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[][]>>> | 54 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[][]>> | 55 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[][]> | 56 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>[]> | 57 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>[]> | 58 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>[]>> | 59 60 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>>> | 61 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>>> | 62 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]>> | 63 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>[]> | 64 65 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>>, 66 depth: 4): U[]; 67 68 /** 69 * Returns a new array with all sub-array elements concatenated into it recursively up to the 70 * specified depth. 71 * 72 * @param depth The maximum recursion depth 73 */ 74 flat<U>(this: 75 ReadonlyArray<U[][][]> | 76 77 ReadonlyArray<ReadonlyArray<U>[][]> | 78 ReadonlyArray<ReadonlyArray<U[]>[]> | 79 ReadonlyArray<ReadonlyArray<U[][]>> | 80 81 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>> | 82 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>> | 83 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]> | 84 85 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>, 86 depth: 3): U[]; 87 88 /** 89 * Returns a new array with all sub-array elements concatenated into it recursively up to the 90 * specified depth. 91 * 92 * @param depth The maximum recursion depth 93 */ 94 flat<U>(this: 95 ReadonlyArray<U[][]> | 96 97 ReadonlyArray<ReadonlyArray<U[]>> | 98 ReadonlyArray<ReadonlyArray<U>[]> | 99 100 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>, 101 depth: 2): U[]; 102 103 /** 104 * Returns a new array with all sub-array elements concatenated into it recursively up to the 105 * specified depth. 106 * 107 * @param depth The maximum recursion depth 108 */ 109 flat<U>(this: 110 ReadonlyArray<U[]> | 111 ReadonlyArray<ReadonlyArray<U>>, 112 depth?: 1 113 ): U[]; 114 115 /** 116 * Returns a new array with all sub-array elements concatenated into it recursively up to the 117 * specified depth. 118 * 119 * @param depth The maximum recursion depth 120 */ 121 flat<U>(this: 122 ReadonlyArray<U>, 123 depth: 0 124 ): U[]; 125 126 /** 127 * Returns a new array with all sub-array elements concatenated into it recursively up to the 128 * specified depth. If no depth is provided, flat method defaults to the depth of 1. 129 * 130 * @param depth The maximum recursion depth 131 */ 132 flat<U>(depth?: number): any[]; 133} 134 135interface Array<T> { 136 137 /** 138 * Calls a defined callback function on each element of an array. Then, flattens the result into 139 * a new array. 140 * This is identical to a map followed by flat with depth 1. 141 * 142 * @param callback A function that accepts up to three arguments. The flatMap method calls the 143 * callback function one time for each element in the array. 144 * @param thisArg An object to which the this keyword can refer in the callback function. If 145 * thisArg is omitted, undefined is used as the this value. 146 */ 147 flatMap<U, This = undefined> ( 148 callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>, 149 thisArg?: This 150 ): U[] 151 152 /** 153 * Returns a new array with all sub-array elements concatenated into it recursively up to the 154 * specified depth. 155 * 156 * @param depth The maximum recursion depth 157 */ 158 flat<U>(this: U[][][][][][][][], depth: 7): U[]; 159 160 /** 161 * Returns a new array with all sub-array elements concatenated into it recursively up to the 162 * specified depth. 163 * 164 * @param depth The maximum recursion depth 165 */ 166 flat<U>(this: U[][][][][][][], depth: 6): U[]; 167 168 /** 169 * Returns a new array with all sub-array elements concatenated into it recursively up to the 170 * specified depth. 171 * 172 * @param depth The maximum recursion depth 173 */ 174 flat<U>(this: U[][][][][][], depth: 5): U[]; 175 176 /** 177 * Returns a new array with all sub-array elements concatenated into it recursively up to the 178 * specified depth. 179 * 180 * @param depth The maximum recursion depth 181 */ 182 flat<U>(this: U[][][][][], depth: 4): U[]; 183 184 /** 185 * Returns a new array with all sub-array elements concatenated into it recursively up to the 186 * specified depth. 187 * 188 * @param depth The maximum recursion depth 189 */ 190 flat<U>(this: U[][][][], depth: 3): U[]; 191 192 /** 193 * Returns a new array with all sub-array elements concatenated into it recursively up to the 194 * specified depth. 195 * 196 * @param depth The maximum recursion depth 197 */ 198 flat<U>(this: U[][][], depth: 2): U[]; 199 200 /** 201 * Returns a new array with all sub-array elements concatenated into it recursively up to the 202 * specified depth. 203 * 204 * @param depth The maximum recursion depth 205 */ 206 flat<U>(this: U[][], depth?: 1): U[]; 207 208 /** 209 * Returns a new array with all sub-array elements concatenated into it recursively up to the 210 * specified depth. 211 * 212 * @param depth The maximum recursion depth 213 */ 214 flat<U>(this: U[], depth: 0): U[]; 215 216 /** 217 * Returns a new array with all sub-array elements concatenated into it recursively up to the 218 * specified depth. If no depth is provided, flat method defaults to the depth of 1. 219 * 220 * @param depth The maximum recursion depth 221 */ 222 flat<U>(depth?: number): any[]; 223} 224