T getFunction(final List<SqlArgument> arguments) {

    // first try to get the candidates without any implicit casting
    Optional<T> candidate = findMatchingCandidate(arguments, false);
    if (candidate.isPresent()) {
      return candidate.get();
    } else if (!supportsImplicitCasts) {
      throw createNoMatchingFunctionException(arguments);
    }

    // if none were found (candidate isn't present) try again with implicit casting
    candidate = findMatchingCandidate(arguments, true);
    if (candidate.isPresent()) {
      return candidate.get();
    }
    throw createNoMatchingFunctionException(arguments);
  }
@Test
  public void shouldChooseCorrectLambdaBiFunction() {
    // Given:
    givenFunctions(
        function(EXPECTED, -1, GENERIC_MAP, LAMBDA_BI_FUNCTION)
    );

    // When:
    final KsqlScalarFunction fun = udfIndex.getFunction(
        ImmutableList.of(
            SqlArgument.of(MAP1_ARG),
            SqlArgument.of(
                SqlLambdaResolved.of(
                    ImmutableList.of(SqlTypes.STRING, SqlTypes.STRING),
                    INTEGER))));

    // Then:
    assertThat(fun.name(), equalTo(EXPECTED));
  }