diff options
author | pacien | 2019-04-05 03:00:45 +0200 |
---|---|---|
committer | pacien | 2019-04-05 03:00:45 +0200 |
commit | 0ac555a6d383fa76626a6123e008365e005558a3 (patch) | |
tree | fbe83c72aea87f342abe80b151edfdcb97cf26a7 /src/main/java/org/pacien | |
parent | 560d8ce7529b634163e53a83461438ebc5ea585c (diff) | |
download | java-lemonad-0ac555a6d383fa76626a6123e008365e005558a3.tar.gz |
add missing map method
Diffstat (limited to 'src/main/java/org/pacien')
-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 | */ |