@stdlib/array
Version:
Arrays.
48 lines (35 loc) • 1.45 kB
Plain Text
{{alias}}( dtype )
Returns an accessor function for retrieving an element from an indexed
array-like object.
An accessor function accepts the following arguments:
- arr: input array.
- idx: element index.
If provided an unsupported `dtype`, the function returns a default accessor
function for accessing elements from any indexed array-like object.
Otherwise, the function returns an accessor function which should *only* be
provided an array instance corresponding to `dtype` (e.g., if `dtype` is
'float64', the returned accessor function should only be provided instances
of Float64Array).
Accessor functions do *not* verify that provided input arrays are array
instances corresponding to `dtype`, as doing so would introduce performance
overhead. If array instances corresponding to other data types are provided
to an accessor function, JavaScript runtimes will consider the function
polymorphic, potentially triggering de-optimization. In order to ensure
maximum performance, *always* ensure that an accessor function is
monomorphic.
Accessor functions do *not* perform bounds checking.
Parameters
----------
dtype: string
Array data type.
Returns
-------
f: Function
Accessor function.
Examples
--------
> var f = {{alias}}( 'generic' );
> var v = f( [ 1, 2, 3, 4 ], 2 )
3
See Also
--------