Kotlin, Reactive programming : How to consume the value of one function output to another one












2















I am very new to Project reactor library and reactive programming with Kotlin, and trying to implement functions like flatmap, flatMapIterable, subscribe etc.
Now issue is I am trying to use the o/p of one function into another one using flatMapIterable, and after using I am trying to subscribe this, by passing the output of fist function and second one to another function of new class.
Now when I try to use the o/p of function 1, I am unable to see the value, I only see Mono<> or Flux<>.



Below is code snippet for more explanation



var result = employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
result.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId) // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(result, it)
}


Now at line 4 I am getting expected userId out of it.userId, but when I inspect result at line 6, then I do not get the expected list of values, it just provides me MonomapFuesable, with mapper and source.



Can anyone please help me to understand what should I do, as my whole agenda is to pass the calculated value from line 1 and line 4 to line 6 function.
Please ask more question, if I haven't provided the required information, I am very new to this.
Thanks in advance !!



[UPDATE] : I have resolved the issue with the following way :
```



employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(it.first, it.second)
}


```










share|improve this question




















  • 1





    I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

    – Mahesh
    Jan 2 at 7:11











  • @Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

    – user10374449
    Jan 2 at 7:20











  • This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

    – JB Nizet
    Jan 2 at 7:59













  • Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

    – user10374449
    Jan 2 at 8:34


















2















I am very new to Project reactor library and reactive programming with Kotlin, and trying to implement functions like flatmap, flatMapIterable, subscribe etc.
Now issue is I am trying to use the o/p of one function into another one using flatMapIterable, and after using I am trying to subscribe this, by passing the output of fist function and second one to another function of new class.
Now when I try to use the o/p of function 1, I am unable to see the value, I only see Mono<> or Flux<>.



Below is code snippet for more explanation



var result = employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
result.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId) // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(result, it)
}


Now at line 4 I am getting expected userId out of it.userId, but when I inspect result at line 6, then I do not get the expected list of values, it just provides me MonomapFuesable, with mapper and source.



Can anyone please help me to understand what should I do, as my whole agenda is to pass the calculated value from line 1 and line 4 to line 6 function.
Please ask more question, if I haven't provided the required information, I am very new to this.
Thanks in advance !!



[UPDATE] : I have resolved the issue with the following way :
```



employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(it.first, it.second)
}


```










share|improve this question




















  • 1





    I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

    – Mahesh
    Jan 2 at 7:11











  • @Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

    – user10374449
    Jan 2 at 7:20











  • This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

    – JB Nizet
    Jan 2 at 7:59













  • Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

    – user10374449
    Jan 2 at 8:34
















2












2








2


0






I am very new to Project reactor library and reactive programming with Kotlin, and trying to implement functions like flatmap, flatMapIterable, subscribe etc.
Now issue is I am trying to use the o/p of one function into another one using flatMapIterable, and after using I am trying to subscribe this, by passing the output of fist function and second one to another function of new class.
Now when I try to use the o/p of function 1, I am unable to see the value, I only see Mono<> or Flux<>.



Below is code snippet for more explanation



var result = employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
result.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId) // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(result, it)
}


Now at line 4 I am getting expected userId out of it.userId, but when I inspect result at line 6, then I do not get the expected list of values, it just provides me MonomapFuesable, with mapper and source.



Can anyone please help me to understand what should I do, as my whole agenda is to pass the calculated value from line 1 and line 4 to line 6 function.
Please ask more question, if I haven't provided the required information, I am very new to this.
Thanks in advance !!



[UPDATE] : I have resolved the issue with the following way :
```



employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(it.first, it.second)
}


```










share|improve this question
















I am very new to Project reactor library and reactive programming with Kotlin, and trying to implement functions like flatmap, flatMapIterable, subscribe etc.
Now issue is I am trying to use the o/p of one function into another one using flatMapIterable, and after using I am trying to subscribe this, by passing the output of fist function and second one to another function of new class.
Now when I try to use the o/p of function 1, I am unable to see the value, I only see Mono<> or Flux<>.



Below is code snippet for more explanation



var result = employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
result.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId) // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(result, it)
}


Now at line 4 I am getting expected userId out of it.userId, but when I inspect result at line 6, then I do not get the expected list of values, it just provides me MonomapFuesable, with mapper and source.



Can anyone please help me to understand what should I do, as my whole agenda is to pass the calculated value from line 1 and line 4 to line 6 function.
Please ask more question, if I haven't provided the required information, I am very new to this.
Thanks in advance !!



[UPDATE] : I have resolved the issue with the following way :
```



employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(it.first, it.second)
}


```







java kotlin reactive-programming project-reactor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 10:05







user10374449

















asked Jan 2 at 7:07









user10374449user10374449

114




114








  • 1





    I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

    – Mahesh
    Jan 2 at 7:11











  • @Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

    – user10374449
    Jan 2 at 7:20











  • This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

    – JB Nizet
    Jan 2 at 7:59













  • Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

    – user10374449
    Jan 2 at 8:34
















  • 1





    I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

    – Mahesh
    Jan 2 at 7:11











  • @Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

    – user10374449
    Jan 2 at 7:20











  • This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

    – JB Nizet
    Jan 2 at 7:59













  • Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

    – user10374449
    Jan 2 at 8:34










1




1





I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

– Mahesh
Jan 2 at 7:11





I think it will help if you list the types returned by each of the variables. At some point an observable is not being returned and that could be the problem.

– Mahesh
Jan 2 at 7:11













@Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

– user10374449
Jan 2 at 7:20





@Mahesh edited the code snippet with comment for each line return type, assuming you are asking for this only

– user10374449
Jan 2 at 7:20













This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

– JB Nizet
Jan 2 at 7:59







This is Kotlin, right? RxJS, as its name indicates, is a JavaScript library. Not a Kotlin or Java library. What you're using (Mono, Flux, etc.) are types from the Reactor library. Not from RxJS. Edit your question, change its title and text and remove the RxJS tag: RxJS has nothing to do with your code.

– JB Nizet
Jan 2 at 7:59















Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

– user10374449
Jan 2 at 8:34







Thanks @JBNizet for correcting me !! Do you have any suggestions/advice for the above questions, Please share your expertise!!

– user10374449
Jan 2 at 8:34














2 Answers
2






active

oldest

votes


















0














It's a bit hard to know for sure from the information supplied above, but I think it looks like the call to employerService.getUsersById isn't returning a Publisher. From your comments I'm guessing it's returning an actual value, GetUserResult, rather than a Mono. Below is a mocked up set of classes which show the desired result, I believe. Maybe compare the below to what you've got and see if you can spot a difference?



data class Employee(val userId: String)
data class GetEmployeeStatusListResult(val emps: List<Employee>)
data class GetUserResult(val employee: Employee)

class EmployerService {
fun getEmployee(status: String) = Mono.just(GetEmployeeStatusListResult(listOf(Employee("a"))))
fun getUsersById(userId: String) = Mono.just(GetUserResult(Employee("a")))
}

fun test() {
val employerService = EmployerService()
employerService
.getEmployee("Active")
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId)
}.subscribe {
// Here "it" is a GetUserResult object
}
}


If, in the subscribe, you need both the initial value retrieved from the call to getEmployee and also the result of the call to getUsersById then you could wrap those two values in a Pair as shown below:



employerService
.getEmployee("Active")
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap { emp ->
employerService.getUsersById(emp.userId).map { emp to it }
}.subscribe {
// Here "it" is a Pair<Employee, GetUserResult>
}





share|improve this answer


























  • I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

    – user10374449
    Jan 3 at 10:06





















0














employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
.flatMapIterable(GetEmployeeStatusListResult::emps)
.flatMap {
employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
}.subscribe {
aService.createContact(it.first, it.second)
}


Adding pair function to fetch both the values and use it in subscribe block !!
Thanks everyone !!






share|improve this answer























    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%2f54002509%2fkotlin-reactive-programming-how-to-consume-the-value-of-one-function-output-t%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It's a bit hard to know for sure from the information supplied above, but I think it looks like the call to employerService.getUsersById isn't returning a Publisher. From your comments I'm guessing it's returning an actual value, GetUserResult, rather than a Mono. Below is a mocked up set of classes which show the desired result, I believe. Maybe compare the below to what you've got and see if you can spot a difference?



    data class Employee(val userId: String)
    data class GetEmployeeStatusListResult(val emps: List<Employee>)
    data class GetUserResult(val employee: Employee)

    class EmployerService {
    fun getEmployee(status: String) = Mono.just(GetEmployeeStatusListResult(listOf(Employee("a"))))
    fun getUsersById(userId: String) = Mono.just(GetUserResult(Employee("a")))
    }

    fun test() {
    val employerService = EmployerService()
    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap {
    employerService.getUsersById(it.userId)
    }.subscribe {
    // Here "it" is a GetUserResult object
    }
    }


    If, in the subscribe, you need both the initial value retrieved from the call to getEmployee and also the result of the call to getUsersById then you could wrap those two values in a Pair as shown below:



    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap { emp ->
    employerService.getUsersById(emp.userId).map { emp to it }
    }.subscribe {
    // Here "it" is a Pair<Employee, GetUserResult>
    }





    share|improve this answer


























    • I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

      – user10374449
      Jan 3 at 10:06


















    0














    It's a bit hard to know for sure from the information supplied above, but I think it looks like the call to employerService.getUsersById isn't returning a Publisher. From your comments I'm guessing it's returning an actual value, GetUserResult, rather than a Mono. Below is a mocked up set of classes which show the desired result, I believe. Maybe compare the below to what you've got and see if you can spot a difference?



    data class Employee(val userId: String)
    data class GetEmployeeStatusListResult(val emps: List<Employee>)
    data class GetUserResult(val employee: Employee)

    class EmployerService {
    fun getEmployee(status: String) = Mono.just(GetEmployeeStatusListResult(listOf(Employee("a"))))
    fun getUsersById(userId: String) = Mono.just(GetUserResult(Employee("a")))
    }

    fun test() {
    val employerService = EmployerService()
    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap {
    employerService.getUsersById(it.userId)
    }.subscribe {
    // Here "it" is a GetUserResult object
    }
    }


    If, in the subscribe, you need both the initial value retrieved from the call to getEmployee and also the result of the call to getUsersById then you could wrap those two values in a Pair as shown below:



    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap { emp ->
    employerService.getUsersById(emp.userId).map { emp to it }
    }.subscribe {
    // Here "it" is a Pair<Employee, GetUserResult>
    }





    share|improve this answer


























    • I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

      – user10374449
      Jan 3 at 10:06
















    0












    0








    0







    It's a bit hard to know for sure from the information supplied above, but I think it looks like the call to employerService.getUsersById isn't returning a Publisher. From your comments I'm guessing it's returning an actual value, GetUserResult, rather than a Mono. Below is a mocked up set of classes which show the desired result, I believe. Maybe compare the below to what you've got and see if you can spot a difference?



    data class Employee(val userId: String)
    data class GetEmployeeStatusListResult(val emps: List<Employee>)
    data class GetUserResult(val employee: Employee)

    class EmployerService {
    fun getEmployee(status: String) = Mono.just(GetEmployeeStatusListResult(listOf(Employee("a"))))
    fun getUsersById(userId: String) = Mono.just(GetUserResult(Employee("a")))
    }

    fun test() {
    val employerService = EmployerService()
    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap {
    employerService.getUsersById(it.userId)
    }.subscribe {
    // Here "it" is a GetUserResult object
    }
    }


    If, in the subscribe, you need both the initial value retrieved from the call to getEmployee and also the result of the call to getUsersById then you could wrap those two values in a Pair as shown below:



    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap { emp ->
    employerService.getUsersById(emp.userId).map { emp to it }
    }.subscribe {
    // Here "it" is a Pair<Employee, GetUserResult>
    }





    share|improve this answer















    It's a bit hard to know for sure from the information supplied above, but I think it looks like the call to employerService.getUsersById isn't returning a Publisher. From your comments I'm guessing it's returning an actual value, GetUserResult, rather than a Mono. Below is a mocked up set of classes which show the desired result, I believe. Maybe compare the below to what you've got and see if you can spot a difference?



    data class Employee(val userId: String)
    data class GetEmployeeStatusListResult(val emps: List<Employee>)
    data class GetUserResult(val employee: Employee)

    class EmployerService {
    fun getEmployee(status: String) = Mono.just(GetEmployeeStatusListResult(listOf(Employee("a"))))
    fun getUsersById(userId: String) = Mono.just(GetUserResult(Employee("a")))
    }

    fun test() {
    val employerService = EmployerService()
    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap {
    employerService.getUsersById(it.userId)
    }.subscribe {
    // Here "it" is a GetUserResult object
    }
    }


    If, in the subscribe, you need both the initial value retrieved from the call to getEmployee and also the result of the call to getUsersById then you could wrap those two values in a Pair as shown below:



    employerService
    .getEmployee("Active")
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap { emp ->
    employerService.getUsersById(emp.userId).map { emp to it }
    }.subscribe {
    // Here "it" is a Pair<Employee, GetUserResult>
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 2 at 9:25

























    answered Jan 2 at 9:15









    Yoni GibbsYoni Gibbs

    1,418114




    1,418114













    • I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

      – user10374449
      Jan 3 at 10:06





















    • I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

      – user10374449
      Jan 3 at 10:06



















    I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

    – user10374449
    Jan 3 at 10:06







    I have resolved this issue by adding Pair only but not in subscribe block but before that, I have updated the question with solution under UPDATE section. Thanks much !!

    – user10374449
    Jan 3 at 10:06















    0














    employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
    .flatMapIterable(GetEmployeeStatusListResult::emps)
    .flatMap {
    employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
    }.subscribe {
    aService.createContact(it.first, it.second)
    }


    Adding pair function to fetch both the values and use it in subscribe block !!
    Thanks everyone !!






    share|improve this answer




























      0














      employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
      .flatMapIterable(GetEmployeeStatusListResult::emps)
      .flatMap {
      employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
      }.subscribe {
      aService.createContact(it.first, it.second)
      }


      Adding pair function to fetch both the values and use it in subscribe block !!
      Thanks everyone !!






      share|improve this answer


























        0












        0








        0







        employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
        .flatMapIterable(GetEmployeeStatusListResult::emps)
        .flatMap {
        employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
        }.subscribe {
        aService.createContact(it.first, it.second)
        }


        Adding pair function to fetch both the values and use it in subscribe block !!
        Thanks everyone !!






        share|improve this answer













        employerService.getEmployee("Active") // return value is Mono<GetEmployeeStatusListResult>
        .flatMapIterable(GetEmployeeStatusListResult::emps)
        .flatMap {
        employerService.getUsersById(it.userId).map{x->Pair(it,x)} // it is of type GetEmployeeStatusListResult.emps and value returned from employerService.getUsersById(it.userId) is of type GetUserResult class created
        }.subscribe {
        aService.createContact(it.first, it.second)
        }


        Adding pair function to fetch both the values and use it in subscribe block !!
        Thanks everyone !!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 10:15









        user10374449user10374449

        114




        114






























            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%2f54002509%2fkotlin-reactive-programming-how-to-consume-the-value-of-one-function-output-t%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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory