Source:
<code>public Optional<ScalarFunctionImplementation> specialize(Signature boundSignature, BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry, boolean isDeterministic) { List<ScalarImplementationChoice> implementationChoices = new ArrayList<ScalarImplementationChoice>(); <START> for (Map.Entry<String, Class<?>> entry : specializedTypeParameters.entrySet()) { <END> if (!entry.getValue().isAssignableFrom(boundVariables.getTypeVariable(entry.getKey()).getJavaType())) { return Optional.empty(); } } if (!returnNativeContainerType.equals(typeManager.getType(boundSignature.getReturnType()).getJavaType())) { return Optional.empty(); } for (ParametricScalarImplementationChoice choice : choices) { for (int i = 0; i < boundSignature.getArgumentTypes().size(); i++) { ScalarFunctionImplementation.ArgumentProperty argumentProperty = choice.getArgumentProperties().get(i); if (boundSignature.getArgumentTypes().get(i).getBase().equals(FunctionType.NAME)) { if (argumentProperty.getArgumentType() != FUNCTION_TYPE) { return Optional.empty(); } } else { if (argumentProperty.getArgumentType() != VALUE_TYPE) { return Optional.empty(); } Class<?> argumentType = typeManager.getType(boundSignature.getArgumentTypes().get(i)).getJavaType(); Class<?> argumentContainerType = getNullAwareContainerType(argumentType, argumentProperty.getNullConvention()); if (!choice.getArgumentNativeContainerTypes().get(i).isAssignableFrom(argumentContainerType)) { return Optional.empty(); } } } MethodHandle boundMethodHandle = bindDependencies(choice.methodHandle, dependencies, boundVariables, typeManager, functionRegistry); Optional<MethodHandle> boundConstructor = choice.constructor.map(handle -> bindDependencies(handle, constructorDependencies, boundVariables, typeManager, functionRegistry)); implementationChoices.add(new ScalarImplementationChoice(choice.nullable, choice.argumentProperties, boundMethodHandle, boundConstructor)); } return Optional.of(new ScalarFunctionImplementation(implementationChoices, isDeterministic)); }</code><technical_language>nit: Remove unused method getNullAwareReturnType</technical_language>

Target:
public Optional<ScalarFunctionImplementation> specialize(Signature boundSignature, BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry, boolean isDeterministic) { List<ScalarImplementationChoice> implementationChoices = new ArrayList<>(); for (Map.Entry<String, Class<?>> entry : specializedTypeParameters.entrySet()) { if (!entry.getValue().isAssignableFrom(boundVariables.getTypeVariable(entry.getKey()).getJavaType())) { return Optional.empty(); } } if (!returnNativeContainerType.equals(typeManager.getType(boundSignature.getReturnType()).getJavaType())) { return Optional.empty(); } for (int i = 0; i < boundSignature.getArgumentTypes().size(); i++) { if (boundSignature.getArgumentTypes().get(i).getBase().equals(FunctionType.NAME)) { if (argumentNativeContainerTypes.get(i).isPresent()) { return Optional.empty(); } } else { if (!argumentNativeContainerTypes.get(i).isPresent()) { return Optional.empty(); } Class<?> argumentType = typeManager.getType(boundSignature.getArgumentTypes().get(i)).getJavaType(); if (!argumentNativeContainerTypes.get(i).get().isAssignableFrom(argumentType)) { return Optional.empty(); } } } for (ParametricScalarImplementationChoice choice : choices) { MethodHandle boundMethodHandle = bindDependencies(choice.methodHandle, choice.getDependencies(), boundVariables, typeManager, functionRegistry); Optional<MethodHandle> boundConstructor = choice.constructor.map(handle -> bindDependencies(handle, choice.getConstructorDependencies(), boundVariables, typeManager, functionRegistry)); implementationChoices.add(new ScalarImplementationChoice(choice.nullable, choice.argumentProperties, boundMethodHandle, boundConstructor)); } return Optional.of(new ScalarFunctionImplementation(implementationChoices, isDeterministic)); }