• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1%# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
2%# Licensed under the Apache License, Version 2.0 (the "License");
3%# you may not use this file except in compliance with the License.
4%# You may obtain a copy of the License at
5%#
6%# http://www.apache.org/licenses/LICENSE-2.0
7%#
8%# Unless required by applicable law or agreed to in writing, software
9%# distributed under the License is distributed on an "AS IS" BASIS,
10%# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11%# See the License for the specific language governing permissions and
12%# limitations under the License.
13%#
14%
15% require_relative 'Array_code'
16
17% TemplateData::get_lambda_data.each { |lambda_args_params|
18%   lambda_params_num, lambda_args, lambda_params = lambda_args_params
19
20/**
21 * Calls a defined callback function on each element of an array, and returns an array that contains the results.
22 *
23 * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
24 *
25 * @returns `Array` instance, constructed from `this` and given function.
26 */
27<%= access_public %> <%= override %> map<%= map_generic %>(<%= this_arg %>callbackfn: (value: <%= el_type %><%= lambda_params %>) => <%= mapped_type %>): <%= array_of_type.(mapped_type) %> {
28    const len = <%= this_len_int %>;
29    let res = <%= make_buffer.('len', mapped_type) %>;
30    for (let i = 0; i < len; i++) {
31        res[i] = callbackfn(<%= get_unsafe.(this, 'i') %><%= lambda_args %>);
32    }
33    return <%= from_buffer.('res', mapped_type) %>;
34}
35% }
36
37/**
38 * Calls a defined callback function on each element of an array, and returns an array that contains the results.
39 *
40 * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
41 *
42 * @returns `Array` instance, constructed from `this` and given function.
43 */
44<%= access_public %> <%= override_expected_here %> map<%= map_generic %>(<%= this_arg %>callbackfn: () => <%= mapped_type %>): <%= array_of_type.(mapped_type) %> {
45    const len = <%= this_len_int %>;
46    let res = <%= make_buffer.('len', mapped_type) %>;
47    for (let i = 0; i < len; i++) {
48        res[i] = callbackfn();
49    }
50    return <%= from_buffer.('res', mapped_type) %>;
51}
52