Interface CheckedFunction<T,R>
- Type Parameters:
T- input type - 输入类型R- return type - 返回值类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
CheckedFunction - Function that can throw checked exceptions
CheckedFunction - 可抛出受检异常的函数
Extends the concept of JDK Function to allow throwing checked exceptions.
This is a local interface for the functional module that mirrors Core's CheckedFunction.
扩展 JDK Function 的概念,支持抛出受检异常。
这是函数式模块的本地接口,与 Core 的 CheckedFunction 对应。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Function (unchecked) - 转换为标准 Function
- Silent execution with defaults - 静默执行并返回默认值
- Composition support (andThen/compose) - 支持函数组合
Usage Examples | 使用示例:
CheckedFunction<Path, String> readFile = path -> Files.readString(path);
Function<Path, String> wrapped = readFile.unchecked();
String content = readFile.applyOrDefault(path, "fallback");
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> CheckedFunction<T, V> andThen(CheckedFunction<? super R, ? extends V> after) Compose with another function (execute this, then after) 与另一个函数组合(先执行本函数,再执行 after)Apply function to argument, may throw checked exception 应用函数到参数,可能抛出受检异常default RapplyOrDefault(T t, R defaultValue) Apply silently, returning default value on exception 静默应用,异常时返回默认值default RapplyQuietly(T t) Apply silently, returning null on exception 静默应用,异常时返回 nulldefault <V> CheckedFunction<V, R> compose(CheckedFunction<? super V, ? extends T> before) Compose with another function (execute before, then this) 与另一个函数组合(先执行 before,再执行本函数)static <T> CheckedFunction<T, T> identity()Create identity function 创建恒等函数static <T,R> CheckedFunction <T, R> Wrap a standard Function as CheckedFunction 将标准 Function 包装为 CheckedFunctionConvert to standard Function, wrapping checked exceptions 转换为标准 Function,包装受检异常
-
Method Details
-
apply
-
unchecked
-
applyQuietly
-
applyOrDefault
-
andThen
Compose with another function (execute this, then after) 与另一个函数组合(先执行本函数,再执行 after)- Type Parameters:
V- result type of after function - after 函数的结果类型- Parameters:
after- function to apply after this - 在本函数之后应用的函数- Returns:
- composed function - 组合后的函数
-
compose
Compose with another function (execute before, then this) 与另一个函数组合(先执行 before,再执行本函数)- Type Parameters:
V- input type of before function - before 函数的输入类型- Parameters:
before- function to apply before this - 在本函数之前应用的函数- Returns:
- composed function - 组合后的函数
-
identity
Create identity function 创建恒等函数- Type Parameters:
T- type - 类型- Returns:
- identity function - 恒等函数
-
of
Wrap a standard Function as CheckedFunction 将标准 Function 包装为 CheckedFunction- Type Parameters:
T- input type - 输入类型R- return type - 返回值类型- Parameters:
function- standard Function - 标准 Function- Returns:
- CheckedFunction wrapper - CheckedFunction 包装器
-