CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
lib.es2019.array.d.ts78 linesDownload Raw Back to lib
1/*! *****************************************************************************2Copyright (c) Microsoft Corporation. All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License"); you may not use4this file except in compliance with the License. You may obtain a copy of the5License at http://www.apache.org/licenses/LICENSE-2.06 7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,10MERCHANTABILITY OR NON-INFRINGEMENT.11 12See the Apache Version 2.0 License for specific language governing permissions13and limitations under the License.14***************************************************************************** */15 16 17type FlatArray<Arr, Depth extends number> = {18    done: Arr;19    recur: Arr extends ReadonlyArray<infer InnerArr> ? 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]>20        : Arr;21}[Depth extends -1 ? "done" : "recur"];22 23interface ReadonlyArray<T> {24    /**25     * Calls a defined callback function on each element of an array. Then, flattens the result into26     * a new array.27     * This is identical to a map followed by flat with depth 1.28     *29     * @param callback A function that accepts up to three arguments. The flatMap method calls the30     * callback function one time for each element in the array.31     * @param thisArg An object to which the this keyword can refer in the callback function. If32     * thisArg is omitted, undefined is used as the this value.33     */34    flatMap<U, This = undefined>(35        callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,36        thisArg?: This,37    ): U[];38 39    /**40     * Returns a new array with all sub-array elements concatenated into it recursively up to the41     * specified depth.42     *43     * @param depth The maximum recursion depth44     */45    flat<A, D extends number = 1>(46        this: A,47        depth?: D,48    ): FlatArray<A, D>[];49}50 51interface Array<T> {52    /**53     * Calls a defined callback function on each element of an array. Then, flattens the result into54     * a new array.55     * This is identical to a map followed by flat with depth 1.56     *57     * @param callback A function that accepts up to three arguments. The flatMap method calls the58     * callback function one time for each element in the array.59     * @param thisArg An object to which the this keyword can refer in the callback function. If60     * thisArg is omitted, undefined is used as the this value.61     */62    flatMap<U, This = undefined>(63        callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,64        thisArg?: This,65    ): U[];66 67    /**68     * Returns a new array with all sub-array elements concatenated into it recursively up to the69     * specified depth.70     *71     * @param depth The maximum recursion depth72     */73    flat<A, D extends number = 1>(74        this: A,75        depth?: D,76    ): FlatArray<A, D>[];77}78