I need to store a list of functions that I can execute from said array.
I also need to be able to pass them as variables.
Lambda doesn’t seem to work in processing. How can I do this?
Thanks!
1 Like
2 Likes
i dont know if you have to use processing, but if you really need lambda expression try using processing as java library from another ide
Can you list all input parameters and all return types.
No inputs, all floats.
Sam Pottinger has done an amazing job in updating processing, not only to update to OpenJDK11, but also to support java 8 syntax in the processing ide. I’m sure he would welcome your support. Here is an example using lambda syntax in the processing ide.
interface MyFunction {
float calculate(float x);
}
float[] values = new float[2];
void setup() {
// lambda expression to define the calculate method
MyFunction doubling = (float x)->x * 2;
values[0] = doubling.calculate(5);
values[1] = doubling.calculate(12);
display();
}
void display() {
println(values[0], values[1]);
}
The code can be even more elegant in JRubyArt
attr_reader :values
def setup
# lambda expression to define the calculate method
doubling = ->(x) { x * 2 }
@values = [5.0, 12.0].map { |x| doubling.call(x) }
display
end
def display
puts values
end
3 Likes
Or as GoToLoop has already posted for the faint hearted see Function as argument of another function, but the update to jdk8 syntax is somewhat overdue.
1 Like