|
1 | 1 | /* |
2 | | - * Copyright 2016 the original author or authors. |
| 2 | + * Copyright 2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -36,17 +36,36 @@ public interface ThrowingFunction<T, R, E extends Exception> { |
36 | 36 | R apply(T arg) throws E; |
37 | 37 |
|
38 | 38 | /** |
| 39 | + * Returns a new Function instance which wraps a result of the given function in an Optional, returning an empty Optional in case of a checked exception |
| 40 | + * |
| 41 | + * @param f operation throwing checked exception |
| 42 | + * @param <T> type of the argument to the function |
| 43 | + * @param <R> type of the result of the function |
39 | 44 | * @return a Function that returns the result of the given function as an Optional instance. |
40 | | - * In case of a failure, empty Optional is returned |
41 | 45 | */ |
42 | 46 | static <T, R> Function<T, Optional<R>> lifted(final ThrowingFunction<T, R, ?> f) { |
43 | 47 | return requireNonNull(f).lift(); |
44 | 48 | } |
45 | 49 |
|
| 50 | + /** |
| 51 | + * Returns a new Function instance which rethrows the checked exception using the Sneaky Throws pattern |
| 52 | + * |
| 53 | + * @param f operation throwing checked exception |
| 54 | + * @param <T> type of the argument to the function |
| 55 | + * @param <R> type of the result of the function |
| 56 | + * @return Function instance that rethrows the checked exception using the Sneaky Throws pattern |
| 57 | + */ |
46 | 58 | static <T, R> Function<T, R> unchecked(final ThrowingFunction<T, R, ?> f) { |
47 | 59 | return requireNonNull(f).uncheck(); |
48 | 60 | } |
49 | 61 |
|
| 62 | + /** |
| 63 | + * Returns a new Function instance which rethrows the checked exception using the Sneaky Throws pattern |
| 64 | + * @param function operation throwing checked exception |
| 65 | + * @param <T1> type of the argument to the function |
| 66 | + * @param <R> type of the result of the function |
| 67 | + * @return Function instance that rethrows the checked exception using the Sneaky Throws pattern |
| 68 | + */ |
50 | 69 | static <T1, R> Function<T1, R> sneaky(ThrowingFunction<? super T1, ? extends R, ?> function) { |
51 | 70 | requireNonNull(function); |
52 | 71 | return t -> { |
|
0 commit comments