kluck
04/19/2019, 2:34 PMfun getStore(): CallK<StoreDto>
. On the repository layer, I'd like to obtain a Store, but as it might come from the network, I guess it should be wrapped in an IO like so: fun getStore(): IO<Store>
.
My problem resides in the fact that I don't find where I should do my mapping from StoreDto to Store. I have something like this for now:
kotlin
apiCall.async(IO.async())
.fix()
.unsafeRunAsync { either ->
either.fold( // <-- the result of this is what I'd like to get
{ IO.raiseError<Store>(it) },
{ retrofitResponse ->
retrofitResponse.unwrapBody(Either.applicativeError()).fix().fold(
{ IO.raiseError(it) },
{ storeDto -> IO.just(Store(storeDto.name)) }
)
}
)
}
But this actually execute the code at the repository level, and doesn't return my expected type. I'd like to actually execute this at a higher level, say my android activity in my presentation layer. Any tips on what direction I should take? I'm trying to get inspiration from https://github.com/JorgeCastilloPrz/ArrowAndroidSamples , but I don't understand all that is done there at the DataSource level…raulraja
04/19/2019, 2:45 PMunsafeRunAsync
raulraja
04/19/2019, 2:45 PMIO
in the return type of your functionsraulraja
04/19/2019, 2:45 PMraulraja
04/19/2019, 2:46 PMapiCall.async(IO.async()).fix().attempt()
raulraja
04/19/2019, 2:46 PMraulraja
04/19/2019, 2:46 PMraulraja
04/19/2019, 2:47 PMkluck
04/19/2019, 2:49 PMraulraja
04/19/2019, 2:49 PMraulraja
04/19/2019, 2:49 PMraulraja
04/19/2019, 2:49 PMattempt
just maps inside IO an attempt operationraulraja
04/19/2019, 2:50 PMraulraja
04/19/2019, 2:50 PMraulraja
04/19/2019, 2:50 PMraulraja
04/19/2019, 2:50 PMkluck
04/19/2019, 2:51 PMraulraja
04/19/2019, 2:52 PMraulraja
04/19/2019, 2:52 PMraulraja
04/19/2019, 2:52 PM!
etc.raulraja
04/19/2019, 2:52 PMraulraja
04/19/2019, 2:53 PMraulraja
04/19/2019, 2:53 PMkluck
04/19/2019, 3:16 PMIO<IO<Store>>
... What am I missing?kluck
04/19/2019, 3:16 PMapiCall.async(IO.async())
.fix()
.attempt()
.map { either ->
either.fold(
{ IO.raiseError<Store>(it) },
{ it.unwrapBody(IO.applicativeError()).fix().map { storeDto -> Store(storeDto.name) } }
)
}
kartoffelsup
04/19/2019, 3:22 PMkluck
04/19/2019, 3:25 PMraulraja
04/19/2019, 3:26 PMapiCall.async(IO.async()).map { Store(it.name) }
raulraja
04/19/2019, 3:26 PMraulraja
04/19/2019, 3:26 PMkluck
04/19/2019, 3:27 PMkluck
04/19/2019, 3:33 PMraulraja
04/19/2019, 3:50 PMstreetsofboston
04/19/2019, 6:01 PMMike
04/20/2019, 3:15 PMraulraja
04/20/2019, 3:26 PMraulraja
04/20/2019, 3:26 PMMike
04/20/2019, 4:22 PMJorge Castillo
04/21/2019, 11:46 AMJorge Castillo
04/21/2019, 11:48 AM