PakhomovAlexander commented on code in PR #1180:
URL: https://github.com/apache/ignite-3/pull/1180#discussion_r991002665


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/flow/builder/FlowBuilderImpl.java:
##########
@@ -69,6 +69,11 @@ public <OT> FlowBuilder<I, OT> then(Flow<O, OT> flow) {
         return new FlowBuilderImpl<>(this.flow.composite(flow), 
exceptionHandlers, decoratorRegistry);
     }
 
+    @Override
+    public <OT> FlowBuilder<I, OT> flatMap(Function<O, FlowBuilder<O, OT>> 
mapper) {
+        return then(it -> mapper.apply(it.value()).build().start(it));
+    }
+
     @Override
     public <OT> FlowBuilder<I, O> ifThen(Predicate<O> tester, Flow<O, OT> 
flow) {

Review Comment:
   should we deprecate `ifThen` or something?



##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/flow/FlowTest.java:
##########
@@ -269,24 +288,27 @@ void customDecorator() throws IOException {
         assertThat(errOut.toString(), emptyString());
     }
 
-    private static Flow<Object, Integer> createFlow() {
-        return askQuestion()
-                .question(s -> "Here is your number " + s + ":, would you like 
to multiply it by 2?",
-                        List.of(new QuestionAnswer<>("yes"::equals, (a, i) -> 
Integer.parseInt(i) * 2),
-                                new QuestionAnswer<>("no"::equals, (a, i) -> 
Integer.parseInt(i))))
-                .ifThen(num -> num == 1, Flows.fromCall(new IntCall(), 
IntCallInput::new))
-                .ifThen(num -> num > 1, Flows.fromCall(new StrCall(), integer 
-> new StrCallInput(String.valueOf(integer))))
-                .build();
+    @Test
+    void flatMap() {
+        Flows.from("fizz")
+                .flatMap(v -> Flows.from(it -> it + "buzz"))
+                .print()
+                .start();
+        assertThat(out.toString(), equalTo("fizzbuzz" + 
System.lineSeparator()));
     }
 
-    private static FlowBuilder<Object, String> askQuestion() {
-        return Flows.question("Do you like this?",
-                        List.of(new QuestionAnswer<>("yes"::equals, (a, i) -> 
1),
-                                new QuestionAnswer<>("no"::equals, (a, i) -> 
2))
-                )
-                .map(String::valueOf);
+    @Test
+    void flatMapInterrupted() {
+        Flows.from("fizz")

Review Comment:
   I would like to see more complex tests, like:
    ```
   Flows.from("fizz")
      .map(v -> Flows.from(it -> it + "1"))
      .print()
      .flatMap(v -> {
                        throw new FlowInterruptException();
                    })
     .print()
     .map(v -> Flows.from(it -> it + "2"))
     .print()
     .start();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to