Daniele B
08/10/2020, 2:04 PMval resp = webservicesAPI.fetchLatest()
resp?.let {
repository.name = resp.name
repository.lastUpdate = resp.lastUpdate
}
diesieben07
08/10/2020, 2:07 PMlet
lambda takes a param:
fetchlatest()?.let { resp ->
repository.lastUpdate = resp.lastUpdate
// etc
}
Daniele B
08/10/2020, 2:08 PMdiesieben07
08/10/2020, 2:09 PMDaniele B
08/10/2020, 2:09 PMmarstran
08/10/2020, 2:21 PMapply
is better here:
webservicesAPI.fetchLatest()
?.apply {
repository.name = name
repository.lastUpdate = lastUpdate
}
Daniele B
08/10/2020, 2:25 PM.apply
running only if fetchLatest()
returns not null ?marstran
08/10/2020, 2:26 PM?
. You still need that. I fixed the code.Daniele B
08/10/2020, 2:26 PMdiesieben07
08/10/2020, 2:26 PMapply
is like let
, except that it uses a lambda wiht receiver instead of a lambda with parameter.marstran
08/10/2020, 2:27 PMDaniele B
08/10/2020, 2:27 PMif (remoteData.lastUpdate == null) {
fetchWeeklyCasesList()
}
do you also have a suggestion to simplify this code?diesieben07
08/10/2020, 2:27 PMDaniele B
08/10/2020, 2:28 PM?
instead of null
?marstran
08/10/2020, 2:29 PMJoost Klitsie
08/11/2020, 6:45 AMval repository = webservicesAPI.fetchLatest()?.let { mapper.map(it) }
So I highly recommend reading this:
https://proandroiddev.com/the-real-repository-pattern-in-android-efba8662b754