import type { array, matrix } from "../types"; /** * Applies a function to each element of a array or matrix. * * This function applies the provided function to each element of a array or matrix. * The first argument is the input array or matrix, the second is the function to apply, followed by any additional parameters required by the function. * * @param x The input array, matrix, or single value to which the function will be applied. * @param fun The function to apply to each element of `x`. * @param [funArgs] Additional arguments to pass to the function `fun` after the current element. * @returns The result of applying the function to each element of the input. Returns a array, matrix, or single value based on input. * * @throws If the input arguments are not valid. * * @example Apply `Math.log` to each element of an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([1.4, 2.3, 3], Math.log), [0.33647223662121284, 0.832909122935104, 1.0986122886681096]); * ``` * * @example Apply the `sign` function to an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([1.4, 0, -10], sign), [1, 0, -1]); * ``` * * @example Apply `Math.pow` to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([[5, 6], [1, 3]], Math.pow, 3), [[125, 216], [1, 27]]); * * ``` * @example Apply the `sign` function to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([[1.4, 0, -10], [2, -3, 4]], sign), [[1, 0, -1], [1, -1, 1]]); * ``` * @example Find substring 'cat' in each element of a nested string array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { strfind } from "../../index.ts"; * * assertEquals( * arrayfun( * [ * ["cat", "concat"], * ["cattle", "catch the catfish"] * ], * strfind, * "cat" * ), * [ * [[0], [3]], * [[0], [0, 10]] * ] * ); * ``` */ export default function arrayfun(x: matrix, fun: (element: T, ...args: A) => U, ...funArgs: A): matrix; /** * Applies a function to each element of a array or matrix. * * This function applies the provided function to each element of a array or matrix. * The first argument is the input array or matrix, the second is the function to apply, followed by any additional parameters required by the function. * * @param x The input array, matrix, or single value to which the function will be applied. * @param fun The function to apply to each element of `x`. * @param [funArgs] Additional arguments to pass to the function `fun` after the current element. * @returns The result of applying the function to each element of the input. Returns a array, matrix, or single value based on input. * * @throws If the input arguments are not valid. * * @example Apply `Math.log` to each element of an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([1.4, 2.3, 3], Math.log), [0.33647223662121284, 0.832909122935104, 1.0986122886681096]); * ``` * * @example Apply the `sign` function to an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([1.4, 0, -10], sign), [1, 0, -1]); * ``` * * @example Apply `Math.pow` to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([[5, 6], [1, 3]], Math.pow, 3), [[125, 216], [1, 27]]); * * ``` * @example Apply the `sign` function to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([[1.4, 0, -10], [2, -3, 4]], sign), [[1, 0, -1], [1, -1, 1]]); * ``` * @example Find substring 'cat' in each element of a nested string array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { strfind } from "../../index.ts"; * * assertEquals( * arrayfun( * [ * ["cat", "concat"], * ["cattle", "catch the catfish"] * ], * strfind, * "cat" * ), * [ * [[0], [3]], * [[0], [0, 10]] * ] * ); * ``` */ export default function arrayfun(x: array, fun: (element: T, ...args: A) => U, ...funArgs: A): array; /** * Applies a function to each element of a array or matrix. * * This function applies the provided function to each element of a array or matrix. * The first argument is the input array or matrix, the second is the function to apply, followed by any additional parameters required by the function. * * @param x The input array, matrix, or single value to which the function will be applied. * @param fun The function to apply to each element of `x`. * @param [funArgs] Additional arguments to pass to the function `fun` after the current element. * @returns The result of applying the function to each element of the input. Returns a array, matrix, or single value based on input. * * @throws If the input arguments are not valid. * * @example Apply `Math.log` to each element of an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([1.4, 2.3, 3], Math.log), [0.33647223662121284, 0.832909122935104, 1.0986122886681096]); * ``` * * @example Apply the `sign` function to an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([1.4, 0, -10], sign), [1, 0, -1]); * ``` * * @example Apply `Math.pow` to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([[5, 6], [1, 3]], Math.pow, 3), [[125, 216], [1, 27]]); * * ``` * @example Apply the `sign` function to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([[1.4, 0, -10], [2, -3, 4]], sign), [[1, 0, -1], [1, -1, 1]]); * ``` * @example Find substring 'cat' in each element of a nested string array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { strfind } from "../../index.ts"; * * assertEquals( * arrayfun( * [ * ["cat", "concat"], * ["cattle", "catch the catfish"] * ], * strfind, * "cat" * ), * [ * [[0], [3]], * [[0], [0, 10]] * ] * ); * ``` */ export default function arrayfun(x: T, fun: (element: T, ...args: A) => U, ...funArgs: A): U; /** * Applies a function to each element of a array or matrix. * * This function applies the provided function to each element of a array or matrix. * The first argument is the input array or matrix, the second is the function to apply, followed by any additional parameters required by the function. * * @param x The input array, matrix, or single value to which the function will be applied. * @param fun The function to apply to each element of `x`. * @param [funArgs] Additional arguments to pass to the function `fun` after the current element. * @returns The result of applying the function to each element of the input. Returns a array, matrix, or single value based on input. * * @throws If the input arguments are not valid. * * @example Apply `Math.log` to each element of an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([1.4, 2.3, 3], Math.log), [0.33647223662121284, 0.832909122935104, 1.0986122886681096]); * ``` * * @example Apply the `sign` function to an array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([1.4, 0, -10], sign), [1, 0, -1]); * ``` * * @example Apply `Math.pow` to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(arrayfun([[5, 6], [1, 3]], Math.pow, 3), [[125, 216], [1, 27]]); * * ``` * @example Apply the `sign` function to each element of a matrix * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { sign } from "../../index.ts"; * * assertEquals(arrayfun([[1.4, 0, -10], [2, -3, 4]], sign), [[1, 0, -1], [1, -1, 1]]); * ``` * @example Find substring 'cat' in each element of a nested string array * ```ts * import { assertEquals } from "jsr:@std/assert"; * import { strfind } from "../../index.ts"; * * assertEquals( * arrayfun( * [ * ["cat", "concat"], * ["cattle", "catch the catfish"] * ], * strfind, * "cat" * ), * [ * [[0], [3]], * [[0], [0, 10]] * ] * ); * ``` */ export default function arrayfun(x: T | array | matrix, fun: (element: T, ...args: A) => U, ...funArgs: A): U | array | matrix; //# sourceMappingURL=arrayfun.d.ts.map