# Arraylist full of functions?

**URL:** <https://discourse.processing.org/t/arraylist-full-of-functions/10786>\
**Category:** Coding Questions\
**Created:** [April 30, 2019, 4:14pm UTC](https://discourse.processing.org/t/arraylist-full-of-functions/10786 "2019-04-30T16:14:45Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [May 2, 2019, 1:01pm UTC](https://discourse.processing.org/t/arraylist-full-of-functions/10786/6 "2019-05-02T13:01:36Z")

</div>

[Sam Pottinger](https://github.com/sampottinger/processing) 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.

 ![lambda](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6329742f95785d58cc270b4c9b2d8888144a1dc6.png)

```java
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](https://ruby-processing.github.io/JRubyArt/)

```ruby
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

```

---

_[View the full topic](https://discourse.processing.org/t/arraylist-full-of-functions/10786)._
