Java Lambda - LongUnaryOperator compose example








LongUnaryOperator compose returns a composed operator that first applies the before operator to its input, and then applies this operator to the result.

Syntax

compose has the following syntax.

default LongUnaryOperator compose(LongUnaryOperator before)

Example

The following example shows how to use compose.

import java.util.function.LongUnaryOperator;
/*ww w .j ava  2 s .c o m*/
public class Main {

  public static void main(String[] args) {
    LongUnaryOperator i = (l) -> -l;
    
    LongUnaryOperator j = (l) -> l/2;
    
    System.out.println(i.compose(j).applyAsLong(Long.MAX_VALUE));
  }
}

The code above generates the following result.