|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +// TypeScript Version: 4.1 |
| 20 | + |
| 21 | +/// <reference types="@stdlib/types"/> |
| 22 | + |
| 23 | +import { Collection, AccessorArrayLike, Complex128Array, Complex64Array } from '@stdlib/types/array'; |
| 24 | + |
| 25 | +/** |
| 26 | +* Returns a new array after updating an index into the input array. |
| 27 | +* |
| 28 | +* If provided an array-like object having a `with` method , the function defers |
| 29 | +* execution to that method and assumes that the method has the following |
| 30 | +* signature: |
| 31 | +* |
| 32 | +* x.with( index, value ) |
| 33 | +* |
| 34 | +* If provided an array-like object without a `with` method, the function manually |
| 35 | +* shallow copied that object and assign provided value to that index. |
| 36 | +* |
| 37 | +* Negative indices are resolved relative to the last array element, with the last |
| 38 | +* element corresponding to `-1`. |
| 39 | +* |
| 40 | +* If provided out-of-bounds indices, the function always returns `undefined`. |
| 41 | +* |
| 42 | +* @param x - input array |
| 43 | +* @param index - element index |
| 44 | +* @param value - replacement value |
| 45 | +* @returns updated array |
| 46 | +* |
| 47 | +* @example |
| 48 | +* var x = [ 1, 2, 3, 4 ]; |
| 49 | +* var out = with( x, 0, 5 ); |
| 50 | +* // returns [ 5, 2, 3, 4 ] |
| 51 | +
|
| 52 | +* @example |
| 53 | +* var out = with( x, -1, 6 ); |
| 54 | +* // returns [ 1, 2, 3, 6 ] |
| 55 | +*/ |
| 56 | + |
| 57 | +/** |
| 58 | + * Sets the value at the specified index in a Complex128Array. |
| 59 | + * |
| 60 | + * @param x - Complex128Array to modify |
| 61 | + * @param index - index at which to set the value |
| 62 | + * @param value - new value to set |
| 63 | + * @returns modified Complex128Array if successful; otherwise, throws a range error. |
| 64 | + */ |
| 65 | +declare function withArray( x: Complex128Array, index: number, value: any ): Complex128Array | void; |
| 66 | + |
| 67 | +/** |
| 68 | + * Sets the value at the specified index in a Complex64Array. |
| 69 | + * |
| 70 | + * @param x - Complex64Array to modify |
| 71 | + * @param index - index at which to set the value |
| 72 | + * @param value - new value to set |
| 73 | + * @returns modified Complex64Array if successful; otherwise, throws a range error |
| 74 | + */ |
| 75 | +declare function withArray( x: Complex64Array, index: number, value: any ): Complex64Array | void; |
| 76 | + |
| 77 | +/** |
| 78 | + * Sets the value at the specified index in an array and returns the modified array. |
| 79 | + * |
| 80 | + * @template T - type of elements in the array |
| 81 | + * @param x - array to modify, which can be either a Collection or an AccessorArrayLike |
| 82 | + * @param index - index at which to set the value |
| 83 | + * @param value - new value to set |
| 84 | + * @returns modified array if successful; otherwise, throws range error |
| 85 | + */ |
| 86 | +declare function withArray< T = unknown >( x: Collection<T> | AccessorArrayLike<T>, index: number, value: any ): Collection<T> | AccessorArrayLike<T> | void; |
| 87 | + |
| 88 | + |
| 89 | +// EXPORTS // |
| 90 | + |
| 91 | +export = withArray; |
0 commit comments