Creates a Function of T
to Unit
from a JavaConsumer.
Creates a Function of T
to Unit
from a JavaConsumer.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.cons; Future<String> fs = Future.value("example"); Future<String> f2 = fs.onSuccess(cons(s -> System.out.println(s))); // or using method references: fs.onSuccess(cons(System.out::println));
Creates an ExceptionalFunction of T
to Unit
from an ExceptionalJavaConsumer.
Creates an ExceptionalFunction of T
to Unit
from an ExceptionalJavaConsumer.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.excons; Future<String> fs = Future.value("example"); Future<String> f2 = fs.onSuccess(excons(s -> { throw new Exception(s); }));
Creates an ExceptionalFunction of T
to R
from an ExceptionalJavaFunction.
Creates an ExceptionalFunction of T
to R
from an ExceptionalJavaFunction.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.exfunc; Future<String> fs = Future.value("example"); Future<Integer> fi = fs.map(exfunc(s -> { throw new Exception(s); }));
Creates an ExceptionalFunction0 to T
from an ExceptionalSupplier.
Creates an ExceptionalFunction0 to T
from an ExceptionalSupplier.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.exRunnable; FuturePool futurePool = FuturePools.immediatePool(); Future<Unit> fu = futurePool.apply(exfunc0(() -> { throw new Exception("blah"); }));
Creates a Function of T
to R
from a JavaFunction.
Creates a Function of T
to R
from a JavaFunction.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.func; Future<String> fs = Future.value("example"); Future<Integer> fi = fs.map(func(s -> s.length())); // or using method references: Future<Integer> fi2 = fs.map(func(String::length));
Creates a Function0 of type-T
from a java.util.function.JavaSupplier
.
Creates a Function0 of type-T
from a java.util.function.JavaSupplier
.
Allows for better interop with Scala from Java 8 using lambdas.
For example:
import com.twitter.util.Future; import static com.twitter.util.Function.func0; Future<String> fs = Future.apply(func0(() -> "example"));
Creates () => A
function (scala.Function0
) from given Callable
.
Creates () => Unit
function (scala.Function0
) from given Runnable
.
Compose a function with a monitor; all invocations of the
returned function are synchronized with the given monitor m
.