is it possible to use IntStream in Processing?

more specifically, a line of code I was hoping to use (or translate) is:

boolean contains = IntStream.of(set02).anyMatch(x -> x == value);

Answers

  • edited May 2018

    https://Forum.Processing.org/two/discussions/tagged?Tag=#lambda

    /**
     * hasNumber() (v1.0)
     * GoToLoop (2018/Apr/08)
     *
     * Forum.Processing.org/two/discussion/27936/
     * is-it-possible-to-use-intstream-in-processing#Item_1
     */
    
    static final int[] VALS = { 3, -6, 10, -2, 0 };
    
    void setup() {
      final boolean has10 = hasNumber(10, VALS);
      println("Got 10:", has10); // true
    
      final boolean hasMinus1 = hasNumber(-1, VALS);
      println("Got -1:", hasMinus1); // false
    
      exit();
    }
    
    @SafeVarargs static final boolean hasNumber(final int num, final int... nums) {
      if (nums != null)  for (final int n : nums)  if (n == num)  return true;
      return false;
    }
    
Sign In or Register to comment.