All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.pincette.function.SideEffect Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package net.pincette.function;

import java.util.function.Supplier;

/**
 * Allows to interleave statements in expressions. You can run it like this:
 *
 * 

{@code final int i = SideEffect.run(() -> doSomething()).andThenGet(() -> 3); } * * @author Werner Donn\u00e9 */ @FunctionalInterface public interface SideEffect extends Runnable { /** * Runs runnable and then returns a SideEffect on which the * andThenGet method can be called. * * @param sideEffect the side effect to be run. * @param the type of the value that will eventually be returned. * @return The SideEffect object. */ static SideEffect run(Runnable sideEffect) { return sideEffect::run; } /** * This method should be called in order for the side effect to execute. * * @param supplier the function that produces the final result. * @return The result of supplier. */ default T andThenGet(Supplier supplier) { run(); return supplier.get(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy