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.


compose has the following syntax.

default LongUnaryOperator compose(LongUnaryOperator before)


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;

The code above generates the following result.