@@ -79,8 +79,8 @@ public final <T extends Throwable> R orThrow(Function<? super L, ? extends T> th
7979 }
8080
8181 /**
82- * If this is a right value, apply pred to it. If the result is true, return the same value; otherwise, return the
83- * result of leftSupplier wrapped as a left value.
82+ * If this is a right value, apply <code> pred</code> to it. If the result is <code> true</code> , return the same
83+ * value; otherwise, return the result of <code> leftSupplier</code> wrapped as a left value.
8484 * <p>
8585 * If this is a left value, return it.
8686 *
@@ -90,7 +90,20 @@ public final <T extends Throwable> R orThrow(Function<? super L, ? extends T> th
9090 * a left
9191 */
9292 public final Either <L , R > filter (Function <? super R , Boolean > pred , Supplier <L > leftSupplier ) {
93- return flatMap (r -> pred .apply (r ) ? right (r ) : left (leftSupplier .get ()));
93+ return filter (pred , __ -> leftSupplier .get ());
94+ }
95+
96+ /**
97+ * If this is a right value, apply <code>pred</code> to it. If the result is <code>true</code>, return the same
98+ * value; otherwise, return the results of applying the right value to <code>leftFn</code> wrapped as a left value.
99+ *
100+ * @param pred the predicate to apply to a right value
101+ * @param leftFn the function from the right value to a left value if pred fails
102+ * @return this is a left value or a right value that pred matches; otherwise, the result of leftFn applied to the
103+ * right value, wrapped in a left
104+ */
105+ public final Either <L , R > filter (Function <? super R , Boolean > pred , Function <? super R , ? extends L > leftFn ) {
106+ return flatMap (r -> pred .apply (r ) ? right (r ) : left (leftFn .apply (r )));
94107 }
95108
96109 /**
0 commit comments