def weld_element_wise_op(array, weld_type, scalar, operation):
    """Applies operation to each element in the array with scalar.

    Parameters
    ----------
    array : numpy.ndarray or WeldObject
        Input array.
    weld_type : WeldType
        Type of each element in the input array.
    scalar : {int, float, str, bool, bytes_}
        Value to compare with; must be same type as the values in the array. If not a str,
        it is casted to weld_type (allowing one to write e.g. native Python int).
    operation : {+, -, *, /, pow}

    Returns
    -------
    WeldObject
        Representation of this computation.

    """
    obj_id, weld_obj = create_weld_object(array)

    scalar = to_weld_literal(scalar, weld_type)

    if operation == 'pow':
        action = 'pow(e, {scalar})'.format(scalar=scalar)
    else:
        action = 'e {operation} {scalar}'.format(scalar=scalar,
                                                 operation=operation)

    weld_template = """result(
    for({array}, 
        appender[{type}], 
        |b: appender[{type}], i: i64, e: {type}| 
            merge(b, {action})
    )
)"""

    weld_obj.weld_code = weld_template.format(array=obj_id,
                                              type=weld_type,
                                              action=action)

    return weld_obj