Commits

Stepan Koltsov committed d90603d

CollectionF.zipWithFlatMapO

(combination of zip and flatMapO)

  • Participants
  • Parent commits d77de3f

Comments (0)

Files changed (2)

src/main/java/ru/yandex/bolts/collection/CollectionF.java

     <B> ListF<B> flatMapW(@FunctionParameter Collection<? extends B> f);
 
     /**
+     * @see #flatMapO(Function)
+     */
+    <B> Tuple2List<E, B> zipWithFlatMapO(Function<? super E, Option<B>> f);
+
+    /**
      * Map to list of map entries and construct map
      * @see #toMap(Function, Function)
      * @see #toTuple2List(Function)

src/main/java/ru/yandex/bolts/collection/impl/AbstractCollectionF.java

         return flatMap(Function.f(f)).uncheckedCast();
     }
 
+    @Override
+    public <B> Tuple2List<E, B> zipWithFlatMapO(Function<? super E, Option<B>> f) {
+        return toList()
+            .zipWith(f)
+            .filterBy2(Option.<B>isDefinedF())
+            .map2(Option.<B>getF())
+        ;
+    }
+
     public final Function1V<E> addOp() {
         return addF();
     }