how to … Rxjava flowable process on get count












0















i recieve a flowable from a call... now i want to check how many items i recieve and then process based on that. I know from a flowable i can get the single count, but im not sure how i could chain this in Rx way..



The below doesnt work... but im a complete noob to Rx :(



  Flowable<Data> dataFlowable = reporter.findData();

Long count = dataFlowable
.count()
.blockingGet();

if(count > 0) {
// do something with the flowable returned
dataFlowable.map(.....);
}


or maybe i can do the following:



dataFlowable.toList().map(list -> processList(list));

public void processList(List<Data> list) {

if(list.size() > 0){
// do something with list
}


thoughts?










share|improve this question





























    0















    i recieve a flowable from a call... now i want to check how many items i recieve and then process based on that. I know from a flowable i can get the single count, but im not sure how i could chain this in Rx way..



    The below doesnt work... but im a complete noob to Rx :(



      Flowable<Data> dataFlowable = reporter.findData();

    Long count = dataFlowable
    .count()
    .blockingGet();

    if(count > 0) {
    // do something with the flowable returned
    dataFlowable.map(.....);
    }


    or maybe i can do the following:



    dataFlowable.toList().map(list -> processList(list));

    public void processList(List<Data> list) {

    if(list.size() > 0){
    // do something with list
    }


    thoughts?










    share|improve this question



























      0












      0








      0








      i recieve a flowable from a call... now i want to check how many items i recieve and then process based on that. I know from a flowable i can get the single count, but im not sure how i could chain this in Rx way..



      The below doesnt work... but im a complete noob to Rx :(



        Flowable<Data> dataFlowable = reporter.findData();

      Long count = dataFlowable
      .count()
      .blockingGet();

      if(count > 0) {
      // do something with the flowable returned
      dataFlowable.map(.....);
      }


      or maybe i can do the following:



      dataFlowable.toList().map(list -> processList(list));

      public void processList(List<Data> list) {

      if(list.size() > 0){
      // do something with list
      }


      thoughts?










      share|improve this question
















      i recieve a flowable from a call... now i want to check how many items i recieve and then process based on that. I know from a flowable i can get the single count, but im not sure how i could chain this in Rx way..



      The below doesnt work... but im a complete noob to Rx :(



        Flowable<Data> dataFlowable = reporter.findData();

      Long count = dataFlowable
      .count()
      .blockingGet();

      if(count > 0) {
      // do something with the flowable returned
      dataFlowable.map(.....);
      }


      or maybe i can do the following:



      dataFlowable.toList().map(list -> processList(list));

      public void processList(List<Data> list) {

      if(list.size() > 0){
      // do something with list
      }


      thoughts?







      rx-java rx-java2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 11:57







      user1555190

















      asked Nov 21 '18 at 11:51









      user1555190user1555190

      92642650




      92642650
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If you want to further process received data after count check, you can use filter() after toList():



          dataFlowable
          .toList() // returns Single<List<Data>>
          .filter(list -> list.size() > 0) // returns Maybe<List<Data>>
          .map(list -> {
          // only called if Maybe contains data (filter condition is true)
          // do something with list
          });





          share|improve this answer
























          • Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

            – user1555190
            Nov 21 '18 at 13:08











          • In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

            – KursoR
            Nov 21 '18 at 13:26











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411460%2fhow-to-rxjava-flowable-process-on-get-count%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you want to further process received data after count check, you can use filter() after toList():



          dataFlowable
          .toList() // returns Single<List<Data>>
          .filter(list -> list.size() > 0) // returns Maybe<List<Data>>
          .map(list -> {
          // only called if Maybe contains data (filter condition is true)
          // do something with list
          });





          share|improve this answer
























          • Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

            – user1555190
            Nov 21 '18 at 13:08











          • In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

            – KursoR
            Nov 21 '18 at 13:26
















          0














          If you want to further process received data after count check, you can use filter() after toList():



          dataFlowable
          .toList() // returns Single<List<Data>>
          .filter(list -> list.size() > 0) // returns Maybe<List<Data>>
          .map(list -> {
          // only called if Maybe contains data (filter condition is true)
          // do something with list
          });





          share|improve this answer
























          • Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

            – user1555190
            Nov 21 '18 at 13:08











          • In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

            – KursoR
            Nov 21 '18 at 13:26














          0












          0








          0







          If you want to further process received data after count check, you can use filter() after toList():



          dataFlowable
          .toList() // returns Single<List<Data>>
          .filter(list -> list.size() > 0) // returns Maybe<List<Data>>
          .map(list -> {
          // only called if Maybe contains data (filter condition is true)
          // do something with list
          });





          share|improve this answer













          If you want to further process received data after count check, you can use filter() after toList():



          dataFlowable
          .toList() // returns Single<List<Data>>
          .filter(list -> list.size() > 0) // returns Maybe<List<Data>>
          .map(list -> {
          // only called if Maybe contains data (filter condition is true)
          // do something with list
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 12:11









          KursoRKursoR

          553513




          553513













          • Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

            – user1555190
            Nov 21 '18 at 13:08











          • In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

            – KursoR
            Nov 21 '18 at 13:26



















          • Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

            – user1555190
            Nov 21 '18 at 13:08











          • In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

            – KursoR
            Nov 21 '18 at 13:26

















          Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

          – user1555190
          Nov 21 '18 at 13:08





          Thanks.. another thing, is it possible to do a blockingGet inside a .map(.. return single.blockingGet..).subscribe(......)

          – user1555190
          Nov 21 '18 at 13:08













          In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

          – KursoR
          Nov 21 '18 at 13:26





          In RxJava almost every possible usage of blockingGet can be expressed via other operators. .map(.. return single.blockingGet..).subscribe(......) can be rewritten with flatMap operator as .flatMap(smth -> single).subscribe()

          – KursoR
          Nov 21 '18 at 13:26




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411460%2fhow-to-rxjava-flowable-process-on-get-count%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()