function optimizeCallback (callback, array, name, isUnary = false) {
  if (typed.isTypedFunction(callback)) {
    let numberOfArguments
    if (isUnary) {
      numberOfArguments = 1
    } else {
      const firstIndex = (array.isMatrix ? array.size() : arraySize(array)).map(() => 0)
      const firstValue = array.isMatrix ? array.get(firstIndex) : get(array, firstIndex)
      numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array)
    }
    let fastCallback
    if (array.isMatrix && (array.dataType !== 'mixed' && array.dataType !== undefined)) {
      const singleSignature = _findSingleSignatureWithArity(callback, numberOfArguments)
      fastCallback = (singleSignature !== undefined) ? singleSignature : callback
    } else {
      fastCallback = callback
    }
    if (numberOfArguments >= 1 && numberOfArguments <= 3) {
      return {
        isUnary: numberOfArguments === 1,
        fn: (...args) => _tryFunctionWithArgs(fastCallback, args.slice(0, numberOfArguments), name, callback.name)
      }
    }
    return { isUnary: false, fn: (...args) => _tryFunctionWithArgs(fastCallback, args, name, callback.name) }
  }
  if (isUnary === undefined) {
    return { isUnary: _findIfCallbackIsUnary(callback), fn: callback }
  } else {
    return { isUnary, fn: callback }
  }
}
Simplifies a callback function by reducing its complexity and potentially improving its performance.

@param {Function} callback The original callback function to simplify.
@param {Array|Matrix} array The array that will be used with the callback function.
@param {string} name The name of the function that is using the callback.
@param {boolean} [isUnary=false] If true, the callback function is unary and will be optimized as such.
@returns {Function} Returns a simplified version of the callback function.