diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/pacien/lemonad/attempt/Attempt.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/java/org/pacien/lemonad/attempt/Attempt.java b/src/main/java/org/pacien/lemonad/attempt/Attempt.java index e36ac4b..9f5befa 100644 --- a/src/main/java/org/pacien/lemonad/attempt/Attempt.java +++ b/src/main/java/org/pacien/lemonad/attempt/Attempt.java | |||
@@ -90,6 +90,17 @@ public interface Attempt<R, E> { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * @param resultMapper a function producing an {@link Attempt}, called with the current result if this {@link Attempt} is a success. | ||
94 | * @param errorMapper a function producing an {@link Attempt}, called with the current error if this {@link Attempt} is a failure. | ||
95 | * @return the transformed {@link Attempt}. | ||
96 | */ | ||
97 | default <RR, EE> Attempt<RR, EE> map(@NonNull Function<? super R, ? extends Attempt<? extends RR, ? extends EE>> resultMapper, | ||
98 | @NonNull Function<? super E, ? extends Attempt<? extends RR, ? extends EE>> errorMapper) { | ||
99 | //noinspection unchecked | ||
100 | return (Attempt<RR, EE>) (isSuccess() ? resultMapper.apply(getResult()) : errorMapper.apply(getError())); | ||
101 | } | ||
102 | |||
103 | /** | ||
93 | * @param mapper a function transforming an {@link Attempt}. | 104 | * @param mapper a function transforming an {@link Attempt}. |
94 | * @return the transformed {@link Attempt} | 105 | * @return the transformed {@link Attempt} |
95 | */ | 106 | */ |