G.3.13 Mapping values in indexed arrays

For the semantics of a “map iteration” see Conventions of the arrays API. For the semantics of a “multi iteration” see Conventions of the arrays API. For the semantics of a “left iteration” see Conventions of the arrays API. For the semantics of a “right iteration” see Conventions of the arrays API.

For the semantics of the parameter OPERATOR see Conventions of the arrays API. For the semantics of the parameter ARRY see Conventions of the arrays API. For the semantics of the parameter ARRYS see Conventions of the arrays API.

Function: mbfl_array_left_map DST_ARRY OPERATOR SRC_ARRY
Function: mbfl_array_right_map DST_ARRY OPERATOR SRC_ARRY

Apply OPERATOR to all the values from SRC_ARRY for the purpose of generating a value to be stored in the homologous slot of DST_ARRY. OPERATOR is used in a command line as follows:

OPERATOR RV VALUE

where: VALUE is a value from ARRY; RV is the variable in which to store the result of OPERATOR’s application. The function mbfl_string_toupper_var() is a valid example of OPERATOR.

mbfl_declare_index_array_varref(DST)
mbfl_declare_index_array_varref(SRC, (a b c))

mbfl_array_left_map mbfl_string_toupper_var _(DST) _(SRC)

mbfl_slots_qvalues(DST) ⇒ A B C
Function: mbfl_multi_array_left_map DST_ARRY OPERATOR SRC_ARRYS
Function: mbfl_multi_array_right_map DST_ARRY OPERATOR SRC_ARRYS

Apply the OPERATOR to every tuple of values in homologous slots from SRC_ARRYS for the purpose of generating result values that are stored in the homologous slot of DST_ARRY. OPERATOR is used in a command line as follows:

OPERATOR RV VALUES

where: VALUES is an index array holding the homologous values from SRC_ARRYS; RV is the variable in which to store the result of OPERATOR’s application.

function operator () {
    mbfl_mandatory_nameref_parameter(RV,     1, reference to result variable)
    mbfl_mandatory_nameref_parameter(VALUES, 2, reference to index array of values)
    declare -i I VALUE=0

    for ((I=0; I < mbfl_slots_number(VALUES); ++I))
    do let VALUE+=mbfl_slot_qref(VALUES, $I)
    done
    RV+=$VALUE
}

mbfl_declare_index_array_varref(ARRY1, (1   2   3   4))
mbfl_declare_index_array_varref(ARRY2, (10  20  30  40))
mbfl_declare_index_array_varref(ARRY3, (100 200 300 400))
mbfl_declare_index_array_varref(ARRYS, (_(ARRY1) _(ARRY2) _(ARRY3)))

mbfl_multi_array_left_map  _(L_RESULT) 'operator' _(ARRYS)
mbfl_multi_array_right_map _(R_RESULT) 'operator' _(ARRYS)

mbfl_slots_qvalues(L_RESULT)    ⇒ 111 222 333 444
mbfl_slots_qvalues(R_RESULT)    ⇒ 111 222 333 444

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.