RxJava2 Iterate list and call single for every item
I have a database table with friend connections:
The next example is just a Imagined
example, so please not suggest me to implement this in another way.
FriendConnection:
- id
- humanId
I have a list with these id's.
val friendConnections = arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
)
I want to make this result list with RxJava.
val friendList = arrayListOf(
Friend(friendConnectionId = 10, humanId = 141, humanInstance = (...)),
Friend(friendConnectionId = 13, humanId = 142, humanInstance = (...))
)
How I can get a human?
fun getHumanById(id: Long) : Single<Human>
So I need to iterate the friendConnections
and make a Single call for every Human. Than I need to map the FriendConnection with the new Human instance to Friend instance.
I tried it but it's not work:
Observable.fromIterable(arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
))
.flatMapSingle { friendConnection ->
repository.getHumanById(friendConnection.humanId)
?.map {human ->
Friend(friendConnection.id,friendConnection.humanId,human)
}
}
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ it ->
Timber.i("friendList is here: $it")
}, {
throw it
})
Someone have idea what's wrong? (I want to implement it with Rx, not with Room)
kotlin rx-java2
|
show 1 more comment
I have a database table with friend connections:
The next example is just a Imagined
example, so please not suggest me to implement this in another way.
FriendConnection:
- id
- humanId
I have a list with these id's.
val friendConnections = arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
)
I want to make this result list with RxJava.
val friendList = arrayListOf(
Friend(friendConnectionId = 10, humanId = 141, humanInstance = (...)),
Friend(friendConnectionId = 13, humanId = 142, humanInstance = (...))
)
How I can get a human?
fun getHumanById(id: Long) : Single<Human>
So I need to iterate the friendConnections
and make a Single call for every Human. Than I need to map the FriendConnection with the new Human instance to Friend instance.
I tried it but it's not work:
Observable.fromIterable(arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
))
.flatMapSingle { friendConnection ->
repository.getHumanById(friendConnection.humanId)
?.map {human ->
Friend(friendConnection.id,friendConnection.humanId,human)
}
}
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ it ->
Timber.i("friendList is here: $it")
}, {
throw it
})
Someone have idea what's wrong? (I want to implement it with Rx, not with Room)
kotlin rx-java2
What result do you have? Why safe call is used inrepository.getHumanById(friendConnection.humanId)?.map
if you havefun getHumanById(id: Long) : Single<Human>
signature?
– ConstOrVar
Nov 21 at 10:57
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is yourrepository.getHumanById
making call to API ?
– Suryavel TR
Nov 21 at 11:20
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
Are you sure thatfun getHumanById(id: Long)
returnsSingle<Human>
and notSingle<Human>?
(nullable type) ?
– Andrey Ilyunin
Nov 21 at 11:47
Because in the expressionrepository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.
– Andrey Ilyunin
Nov 21 at 11:49
|
show 1 more comment
I have a database table with friend connections:
The next example is just a Imagined
example, so please not suggest me to implement this in another way.
FriendConnection:
- id
- humanId
I have a list with these id's.
val friendConnections = arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
)
I want to make this result list with RxJava.
val friendList = arrayListOf(
Friend(friendConnectionId = 10, humanId = 141, humanInstance = (...)),
Friend(friendConnectionId = 13, humanId = 142, humanInstance = (...))
)
How I can get a human?
fun getHumanById(id: Long) : Single<Human>
So I need to iterate the friendConnections
and make a Single call for every Human. Than I need to map the FriendConnection with the new Human instance to Friend instance.
I tried it but it's not work:
Observable.fromIterable(arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
))
.flatMapSingle { friendConnection ->
repository.getHumanById(friendConnection.humanId)
?.map {human ->
Friend(friendConnection.id,friendConnection.humanId,human)
}
}
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ it ->
Timber.i("friendList is here: $it")
}, {
throw it
})
Someone have idea what's wrong? (I want to implement it with Rx, not with Room)
kotlin rx-java2
I have a database table with friend connections:
The next example is just a Imagined
example, so please not suggest me to implement this in another way.
FriendConnection:
- id
- humanId
I have a list with these id's.
val friendConnections = arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
)
I want to make this result list with RxJava.
val friendList = arrayListOf(
Friend(friendConnectionId = 10, humanId = 141, humanInstance = (...)),
Friend(friendConnectionId = 13, humanId = 142, humanInstance = (...))
)
How I can get a human?
fun getHumanById(id: Long) : Single<Human>
So I need to iterate the friendConnections
and make a Single call for every Human. Than I need to map the FriendConnection with the new Human instance to Friend instance.
I tried it but it's not work:
Observable.fromIterable(arrayListOf(
FriendConnection(id=10, humanId=141),
FriendConnection(id=13, humanId=142)
))
.flatMapSingle { friendConnection ->
repository.getHumanById(friendConnection.humanId)
?.map {human ->
Friend(friendConnection.id,friendConnection.humanId,human)
}
}
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ it ->
Timber.i("friendList is here: $it")
}, {
throw it
})
Someone have idea what's wrong? (I want to implement it with Rx, not with Room)
kotlin rx-java2
kotlin rx-java2
edited Nov 21 at 10:12
asked Nov 21 at 10:07
vihkat
236315
236315
What result do you have? Why safe call is used inrepository.getHumanById(friendConnection.humanId)?.map
if you havefun getHumanById(id: Long) : Single<Human>
signature?
– ConstOrVar
Nov 21 at 10:57
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is yourrepository.getHumanById
making call to API ?
– Suryavel TR
Nov 21 at 11:20
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
Are you sure thatfun getHumanById(id: Long)
returnsSingle<Human>
and notSingle<Human>?
(nullable type) ?
– Andrey Ilyunin
Nov 21 at 11:47
Because in the expressionrepository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.
– Andrey Ilyunin
Nov 21 at 11:49
|
show 1 more comment
What result do you have? Why safe call is used inrepository.getHumanById(friendConnection.humanId)?.map
if you havefun getHumanById(id: Long) : Single<Human>
signature?
– ConstOrVar
Nov 21 at 10:57
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is yourrepository.getHumanById
making call to API ?
– Suryavel TR
Nov 21 at 11:20
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
Are you sure thatfun getHumanById(id: Long)
returnsSingle<Human>
and notSingle<Human>?
(nullable type) ?
– Andrey Ilyunin
Nov 21 at 11:47
Because in the expressionrepository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.
– Andrey Ilyunin
Nov 21 at 11:49
What result do you have? Why safe call is used in
repository.getHumanById(friendConnection.humanId)?.map
if you have fun getHumanById(id: Long) : Single<Human>
signature?– ConstOrVar
Nov 21 at 10:57
What result do you have? Why safe call is used in
repository.getHumanById(friendConnection.humanId)?.map
if you have fun getHumanById(id: Long) : Single<Human>
signature?– ConstOrVar
Nov 21 at 10:57
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is your
repository.getHumanById
making call to API ?– Suryavel TR
Nov 21 at 11:20
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is your
repository.getHumanById
making call to API ?– Suryavel TR
Nov 21 at 11:20
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
Are you sure that
fun getHumanById(id: Long)
returns Single<Human>
and not Single<Human>?
(nullable type) ?– Andrey Ilyunin
Nov 21 at 11:47
Are you sure that
fun getHumanById(id: Long)
returns Single<Human>
and not Single<Human>?
(nullable type) ?– Andrey Ilyunin
Nov 21 at 11:47
Because in the expression
repository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.– Andrey Ilyunin
Nov 21 at 11:49
Because in the expression
repository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.– Andrey Ilyunin
Nov 21 at 11:49
|
show 1 more comment
2 Answers
2
active
oldest
votes
Is this solution suitable for you?
Observable.fromIterable(
listOf(
FriendConnection(1, 101),
FriendConnection(2, 102)
)
)
.flatMapSingle { connection ->
getHumanById(connection.humanId)
.map { human -> Friend(connection.id, connection.humanId, human) }
}
.toList()
.subscribe { list -> println(list) } //method reference generates error due to methods ambiguity
Mock function for getting a human by id:
private fun getHumanById(id: Long): Single<Human> = Single.just(Human(id, id.toString()))
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure thatgetHumanById
returns exactlySingle<Human>
? It is not eitherSingle<Human?>
orSingle<Human>?
or evenSingle<Human?>?
?
– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
|
show 1 more comment
You could do something like this,
Observable.fromIterable(friendConnections)
.flatMap { Observable.just(Friend(it.id, it.humanId, repository.getHumanById(it.humanId).blockingGet())) }
.toList()
.subscribe {it --> /*Your Operation*/
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. ifrepository.getHumanById
makes API call then it should beflatMap
. (Updated the answer based on assumption)
– Suryavel TR
Nov 21 at 11:42
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409630%2frxjava2-iterate-list-and-call-single-for-every-item%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
Is this solution suitable for you?
Observable.fromIterable(
listOf(
FriendConnection(1, 101),
FriendConnection(2, 102)
)
)
.flatMapSingle { connection ->
getHumanById(connection.humanId)
.map { human -> Friend(connection.id, connection.humanId, human) }
}
.toList()
.subscribe { list -> println(list) } //method reference generates error due to methods ambiguity
Mock function for getting a human by id:
private fun getHumanById(id: Long): Single<Human> = Single.just(Human(id, id.toString()))
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure thatgetHumanById
returns exactlySingle<Human>
? It is not eitherSingle<Human?>
orSingle<Human>?
or evenSingle<Human?>?
?
– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
|
show 1 more comment
Is this solution suitable for you?
Observable.fromIterable(
listOf(
FriendConnection(1, 101),
FriendConnection(2, 102)
)
)
.flatMapSingle { connection ->
getHumanById(connection.humanId)
.map { human -> Friend(connection.id, connection.humanId, human) }
}
.toList()
.subscribe { list -> println(list) } //method reference generates error due to methods ambiguity
Mock function for getting a human by id:
private fun getHumanById(id: Long): Single<Human> = Single.just(Human(id, id.toString()))
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure thatgetHumanById
returns exactlySingle<Human>
? It is not eitherSingle<Human?>
orSingle<Human>?
or evenSingle<Human?>?
?
– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
|
show 1 more comment
Is this solution suitable for you?
Observable.fromIterable(
listOf(
FriendConnection(1, 101),
FriendConnection(2, 102)
)
)
.flatMapSingle { connection ->
getHumanById(connection.humanId)
.map { human -> Friend(connection.id, connection.humanId, human) }
}
.toList()
.subscribe { list -> println(list) } //method reference generates error due to methods ambiguity
Mock function for getting a human by id:
private fun getHumanById(id: Long): Single<Human> = Single.just(Human(id, id.toString()))
Is this solution suitable for you?
Observable.fromIterable(
listOf(
FriendConnection(1, 101),
FriendConnection(2, 102)
)
)
.flatMapSingle { connection ->
getHumanById(connection.humanId)
.map { human -> Friend(connection.id, connection.humanId, human) }
}
.toList()
.subscribe { list -> println(list) } //method reference generates error due to methods ambiguity
Mock function for getting a human by id:
private fun getHumanById(id: Long): Single<Human> = Single.just(Human(id, id.toString()))
answered Nov 21 at 11:45
Andrey Ilyunin
1,259220
1,259220
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure thatgetHumanById
returns exactlySingle<Human>
? It is not eitherSingle<Human?>
orSingle<Human>?
or evenSingle<Human?>?
?
– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
|
show 1 more comment
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure thatgetHumanById
returns exactlySingle<Human>
? It is not eitherSingle<Human?>
orSingle<Human>?
or evenSingle<Human?>?
?
– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
This does not work for me. I have 50 item in the friendConnection list, but only first 2 times called the flatMapSingle, why?
– vihkat
Nov 21 at 11:56
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
@vihkat, please, answer my comment under the question. Maybe the problem lies here. Also, it would be cool if we could know why it does not work. Compile-time error, run-time error, unexpected result?
– Andrey Ilyunin
Nov 21 at 11:57
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
It works with your mock. But not work with my Single, but I'm sure it not returning null because I burned in a fix ID witch is work good
– vihkat
Nov 21 at 12:02
Are you completely sure that
getHumanById
returns exactly Single<Human>
? It is not either Single<Human?>
or Single<Human>?
or even Single<Human?>?
?– Andrey Ilyunin
Nov 21 at 12:29
Are you completely sure that
getHumanById
returns exactly Single<Human>
? It is not either Single<Human?>
or Single<Human>?
or even Single<Human?>?
?– Andrey Ilyunin
Nov 21 at 12:29
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
Yes. I'm sure about it
– vihkat
Nov 21 at 12:33
|
show 1 more comment
You could do something like this,
Observable.fromIterable(friendConnections)
.flatMap { Observable.just(Friend(it.id, it.humanId, repository.getHumanById(it.humanId).blockingGet())) }
.toList()
.subscribe {it --> /*Your Operation*/
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. ifrepository.getHumanById
makes API call then it should beflatMap
. (Updated the answer based on assumption)
– Suryavel TR
Nov 21 at 11:42
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
add a comment |
You could do something like this,
Observable.fromIterable(friendConnections)
.flatMap { Observable.just(Friend(it.id, it.humanId, repository.getHumanById(it.humanId).blockingGet())) }
.toList()
.subscribe {it --> /*Your Operation*/
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. ifrepository.getHumanById
makes API call then it should beflatMap
. (Updated the answer based on assumption)
– Suryavel TR
Nov 21 at 11:42
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
add a comment |
You could do something like this,
Observable.fromIterable(friendConnections)
.flatMap { Observable.just(Friend(it.id, it.humanId, repository.getHumanById(it.humanId).blockingGet())) }
.toList()
.subscribe {it --> /*Your Operation*/
You could do something like this,
Observable.fromIterable(friendConnections)
.flatMap { Observable.just(Friend(it.id, it.humanId, repository.getHumanById(it.humanId).blockingGet())) }
.toList()
.subscribe {it --> /*Your Operation*/
edited Nov 21 at 12:12
answered Nov 21 at 11:18
Suryavel TR
2,36311418
2,36311418
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. ifrepository.getHumanById
makes API call then it should beflatMap
. (Updated the answer based on assumption)
– Suryavel TR
Nov 21 at 11:42
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
add a comment |
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. ifrepository.getHumanById
makes API call then it should beflatMap
. (Updated the answer based on assumption)
– Suryavel TR
Nov 21 at 11:42
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
1
1
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
you need flatMap for getHumanById, not map
– Tim Castelijns
Nov 21 at 11:28
True. if
repository.getHumanById
makes API call then it should be flatMap
. (Updated the answer based on assumption)– Suryavel TR
Nov 21 at 11:42
True. if
repository.getHumanById
makes API call then it should be flatMap
. (Updated the answer based on assumption)– Suryavel TR
Nov 21 at 11:42
1
1
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
there is no assumption, it doesn't matter what the method is doing. It returns a Single, therefore you need flatMap
– Tim Castelijns
Nov 21 at 11:43
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409630%2frxjava2-iterate-list-and-call-single-for-every-item%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What result do you have? Why safe call is used in
repository.getHumanById(friendConnection.humanId)?.map
if you havefun getHumanById(id: Long) : Single<Human>
signature?– ConstOrVar
Nov 21 at 10:57
Why you want to do this with Rx ? you can achieve this using kotlin operators itself. is your
repository.getHumanById
making call to API ?– Suryavel TR
Nov 21 at 11:20
No, it's just a local database call.
– vihkat
Nov 21 at 11:39
Are you sure that
fun getHumanById(id: Long)
returnsSingle<Human>
and notSingle<Human>?
(nullable type) ?– Andrey Ilyunin
Nov 21 at 11:47
Because in the expression
repository.getHumanById(friendConnection.humanId)?.map {...}
question mark denotes nullable type.– Andrey Ilyunin
Nov 21 at 11:49