Here's a basic example demonstrating how to use Pipe4j:
packagecom.example.demo;importio.igventurelli.Pipe4j;importjava.util.Random;publicclassDemoApplication {publicstaticvoidmain(String[] args) {var random =newRandom().nextInt(100);var pipe =Pipe4j.from(10).perform(input -> input *2) // input = 10 - from the previous step.perform(res -> res /4) // res = 20 - result of the multiply operation from the previous step.perform(res ->newSomeService().shallIThrowException(random %2==0, res), e -> { System.out.println("An exception has been thrown: [" + e.getMessage() + "] - Providing fallback value:");
return99; // default value in case of exception }).get();System.out.println(pipe); }privatestaticclassSomeService {publicStringshallIThrowException(boolean shallI,Integer operand) throwsException {if (shallI) {thrownewException("A checked exception has been thrown"); }return"It works, your result is: "+ operand; } }}