def METHOD_NAME(array, mask, valid_when, highlevel, behavior):
    def action(inputs, backend, **kwargs):
        layoutarray, layoutmask = inputs
        if isinstance(layoutmask, ak.contents.NumpyArray):
            m = backend.nplike.asarray(layoutmask)
            if not issubclass(m.dtype.type, (bool, np.bool_)):
                raise ValueError(f"mask must have boolean type, not {m.dtype!r}")
            bytemask = ak.index.Index8(m.view(np.int8))
            return (
                ak.contents.ByteMaskedArray.simplified(
                    bytemask, layoutarray, valid_when=valid_when
                ),
            )
        else:
            return None
    layoutarray = ak.operations.to_layout(array, allow_record=False, allow_other=False)
    layoutmask = ak.operations.to_layout(mask, allow_record=False, allow_other=False)
    behavior = behavior_of(array, mask, behavior=behavior)
    out = ak._broadcasting.broadcast_and_apply(
        [layoutarray, layoutmask],
        action,
        behavior,
        numpy_to_regular=True,
        right_broadcast=False,
    )
    assert isinstance(out, tuple) and len(out) == 1
    return wrap_layout(out[0], behavior, highlevel)