@@ -0,0 +1,1414 @@
+%0Apackage net.restlesscoder.sandbox;%0A%0Aimport java.util.Arrays;%0Aimport java.util.function.Function;%0A%0Aimport org.python.core.Py;%0Aimport org.python.core.PyObject;%0Aimport org.scijava.Context;%0Aimport org.scijava.script.ScriptModule;%0Aimport org.scijava.script.ScriptService;%0A%0Apublic class ConvertPythonFunctionToJava %7B%0A%0A%09public static void main(final String... args) throws Throwable %7B%0A%09%09final Context ctx = new Context();%0A%0A%09%09// Define a Python function as a script output.%0A%09%09final String script = %22#@output Object hello%5Cn%22 + //%0A%09%09%09%22%5Cn%22 + //%0A%09%09%09%22def hello(name):%5Cn%22 + //%0A%09%09%09%22%5Ctreturn %5C%22Hello, %5C%22 + str(name) + %5C%22!%5C%22%5Cn%22 + //%0A%09%09%09%22%5Cn%22;%0A%0A%09%09// Execute the script.%0A%09%09final ScriptModule m = ctx.service(ScriptService.class).run(%22func.py%22,%0A%09%09%09script, false).get();%0A%0A%09%09// Extract the Python function object.%0A%09%09final Object hello = m.getOutput(%22hello%22);%0A%09%09final PyObject pyFunc = (PyObject) hello;%0A%09%09if (!pyFunc.isCallable()) %7B%0A%09%09%09throw new IllegalStateException(%22expected callable Python object%22);%0A%09%09%7D%0A%0A%09%09// Convert the Python function to a Java function.%0A%09%09final Function%3CObject, Object%3E func = t -%3E pyFunc.__call__(%0A%09%09%09t instanceof Object%5B%5D ? pyArgs((Object%5B%5D) t) : pyArgs(t));%0A%0A%09%09// Try out our shiny new Java function.%0A%09%09System.out.println(func.apply(%22Curtis%22));%0A%09%7D%0A%0A%09private static PyObject%5B%5D pyArgs(final Object... o) %7B%0A%09%09if (o == null) return null;%0A%09%09return Arrays.stream(o).map(Py::java2py).toArray(PyObject%5B%5D::new);%0A%09%7D%0A%7D%0A

Add example converting PyFunction to Function