@@ -87,10 +87,10 @@ public static <L, R> Either<L, R> right(R value) {
8787 * @param <R2> the new RHS type
8888 * @return an equivalent instance if this is a Left, otherwise a Right containing
8989 * the result of applying {@code mapper} to the RHS value
90+ * @throws NullPointerException if the {@code mapper} returns a {@code null} result
9091 */
91- public final <R2 > Either <L , R2 > map (Function <? super R , ? extends R2 > mapper ) {
92- return fold (Either ::left , r -> right (mapper .apply (r )));
93- }
92+ public abstract <R2 > Either <L , R2 > map (
93+ Function <? super R , ? extends R2 > mapper );
9494
9595 /**
9696 * If this is a Right, returns the result of applying the mapper function to the RHS value.
@@ -101,22 +101,21 @@ public final <R2> Either<L, R2> map(Function<? super R, ? extends R2> mapper) {
101101 * @return an equivalent instance if this is a Left, otherwise the result of
102102 * applying {@code mapper} to the RHS value
103103 */
104- public final <R2 > Either <L , R2 > flatMap (
105- Function <? super R , ? extends Either <? extends L , ? extends R2 >> mapper ) {
106- return fold (Either ::left , r -> narrow (mapper .apply (r )));
107- }
104+ public abstract <R2 > Either <L , R2 > flatMap (
105+ Function <? super R , ? extends Either <? extends L , ? extends R2 >> mapper );
108106
109107 /**
110108 * If this is a Left, returns a Left containing the LHS value.
111109 * If this is a Right, applies the predicate function to the RHS value.
112110 * If the predicate function returns an empty result,
113111 * returns a Right containing the RHS value.
114- * If the result is not empty, returns a Left containing that result.
112+ * If the result is not empty, returns a Left containing the result.
115113 *
116114 * @param predicate a function that acts as a filter predicate
117115 * @return filter result
118116 */
119- public abstract Either <L , R > filter (Function <? super R , LeftOptional <? extends L >> predicate );
117+ public abstract Either <L , R > filter (
118+ Function <? super R , LeftOptional <? extends L >> predicate );
120119
121120 /**
122121 * If this is a Left, returns a Left containing the result of applying the mapper function to the LHS value.
@@ -126,8 +125,10 @@ public final <R2> Either<L, R2> flatMap(
126125 * @param <L2> the new LHS type
127126 * @return an equivalent instance if this is a Right, otherwise a Left containing
128127 * the result of applying {@code mapper} to the LHS value
128+ * @throws NullPointerException if the {@code mapper} returns a {@code null} result
129129 */
130- public abstract <L2 > Either <L2 , R > mapLeft (Function <? super L , ? extends L2 > mapper );
130+ public abstract <L2 > Either <L2 , R > mapLeft (
131+ Function <? super L , ? extends L2 > mapper );
131132
132133 /**
133134 * If this is a Left, returns the result of applying the mapper function to the LHS value.
@@ -141,6 +142,19 @@ public final <R2> Either<L, R2> flatMap(
141142 public abstract <L2 > Either <L2 , R > flatMapLeft (
142143 Function <? super L , ? extends Either <? extends L2 , ? extends R >> mapper );
143144
145+ /**
146+ * If this is a Right, returns a Right containing the RHS value.
147+ * If this is a Left, applies the predicate function to the LHS value.
148+ * If the predicate function returns an empty result,
149+ * returns a Left containing the LHS value.
150+ * If the result is not empty, returns a Right containing the result.
151+ *
152+ * @param predicate a function that acts as a filter predicate
153+ * @return filter result
154+ */
155+ public abstract Either <L , R > filterLeft (
156+ Function <? super L , Optional <? extends R >> predicate );
157+
144158 /**
145159 * If this is a Right, returns the RHS value.
146160 * Otherwise throws an exception produced by the exception supplying function.
@@ -150,7 +164,8 @@ public abstract <L2> Either<L2, R> flatMapLeft(
150164 * @return the RHS value, if this is a Right
151165 * @throws X the result of applying {@code exceptionSupplier} to the LHS value, if this is a Left
152166 */
153- public abstract <X extends Throwable > R orElseThrow (Function <? super L , ? extends X > exceptionSupplier ) throws X ;
167+ public abstract <X extends Throwable > R orElseThrow (
168+ Function <? super L , ? extends X > exceptionSupplier ) throws X ;
154169
155170 /**
156171 * If this is a Left, returns the result of applying the {@code leftMapper} to the LHS value.
@@ -165,15 +180,16 @@ public abstract <U> U fold(
165180 Function <? super L , ? extends U > leftMapper ,
166181 Function <? super R , ? extends U > rightMapper );
167182
168-
169183 /**
170184 * If this is a Left, performs the {@code leftAction} with the LHS value.
171185 * Otherwise performs the {@code rightAction} with the RHS value.
172186 *
173187 * @param leftAction action to run if this is a Left
174188 * @param rightAction action to run if this is a Right
175189 */
176- public abstract void ifPresentOrElse (Consumer <? super L > leftAction , Consumer <? super R > rightAction );
190+ public abstract void ifPresentOrElse (
191+ Consumer <? super L > leftAction ,
192+ Consumer <? super R > rightAction );
177193
178194 /**
179195 * Returns {@code true} if this is a Left, otherwise {@code false}.
0 commit comments