Min / max lambda expression in java

Is there a (elegant) way to define a min / max lambda expression?

public class MathFunction{
  private java.util.function.Function <double[], Double> function = null; 
  public MathFunction ( Function <double[], Double> pFunction ){    
     this.function = pFunction;   
  }
}
// now defining a min-function...
MathFunction func = new MathFunction((x) -> min(x));

Of course, it min(x)does n’t work . I need a way to sort an array on the fly.

+4
source share
1 answer

You can pass an array and extract from it min:

MathFunction func = 
    new MathFunction((x) -> Arrays.stream(x).min().getAsDouble());
+3
source

Source: https://habr.com/ru/post/1615800/


All Articles