File tree Expand file tree Collapse file tree
microsphere-java-core/src/main/java/io/microsphere/lang/function Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222import static io .microsphere .util .Assert .assertNotNull ;
2323
2424/**
25- * {@link Function} with {@link Throwable}
25+ * Represents a function that accepts one argument and produces a result, which may throw a checked exception.
26+ * <p>
27+ * This interface is similar to {@link Function}, but allows the functional method to throw any {@link Throwable}.
28+ * It also provides default methods for composing functions and handling exceptions gracefully.
29+ * </p>
2630 *
27- * @param <T> the source type
28- * @param <R> the return type
31+ * <h2>Examples</h2>
32+ * <pre>{@code
33+ * // Example usage:
34+ * ThrowableFunction<String, Integer> parser = Integer::valueOf;
35+ *
36+ * // Using execute() with default exception handling (throws RuntimeException)
37+ * Integer result1 = parser.execute("123"); // returns 123
38+ *
39+ * // Using execute() with custom exception handling
40+ * Integer result2 = parser.execute("invalid", (input, ex) -> {
41+ * System.out.println("Parsing failed for: " + input);
42+ * return -1; // fallback value
43+ * });
44+ * }</pre>
45+ *
46+ * @param <T> the type of the input to the function
47+ * @param <R> the type of the result of the function
48+ * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
2949 * @see Function
3050 * @see Throwable
3151 * @since 1.0.0
You can’t perform that action at this time.
0 commit comments