Concepts

from()

The from() method initializes the pipeline. The argument passed to this method becomes the input for the next perform() call in the chain.

var pipe = Pipe4j.from(10)

perform()

The perform() method is used to chain actions. It has two overloads:

  1. Without Exception Handling: Accepts a single callable action that returns a result.

    pipe.perform(input -> input * 2)
  2. With Exception Handling: Accepts a callable action and an exception handler. The exception handler is a function that takes a Throwable and returns a fallback value or throws a new RuntimeException.

    pipe.perform(res -> new SomeService().shallIThrowException(random % 2 == 0, res), e -> {
        return 99; // Fallback value in case of exception
    })

get()

The get() method terminates the pipeline and returns the final value produced by the last perform() call.

var result = pipe.get();

Last updated