Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow Homework #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Flow Homework #68

wants to merge 3 commits into from

Conversation

yeliseyL
Copy link

@yeliseyL yeliseyL commented May 1, 2022

No description provided.

.transform { number ->
when {
number % 15 == 0 -> {
emit(number.toString())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emit(number.toString()) можно вынести за when, чтобы не писать его три раза

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

@@ -48,6 +72,11 @@ class SampleInteractor(
* При любом исходе, будь то выброс исключения или успешная отработка функции вызовите метод dotsRepository.completed()
*/
fun task4(): Flow<Int> {
return flowOf()
return sampleRepository.produceNumbers()
.catch { e ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если флоу produceNumbers() завершится без ошибки, то условие задачи не выполнится (sampleRepository.completed() не будет вызван)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

@@ -18,7 +19,12 @@ class SampleInteractor(
* 6) возвращает результат
*/
fun task1(): Flow<String> {
return flowOf()
return sampleRepository.produceNumbers()
.transform { emit(it.toFloat().pow(5)) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно использовать map тут и тремя строчками ниже, он попроще выглядит чем transform

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

private val _catsLiveData = MutableLiveData<Fact>()
val catsLiveData: LiveData<Fact> = _catsLiveData
private val _catsFlow = MutableStateFlow<Result<Fact>>(Result.Success(Fact("", false, "", "", "", false, "", "", "")))
val catsFlow : StateFlow<Result<Fact>> = _catsFlow

init {
viewModelScope.launch {
withContext(Dispatchers.IO) {
catsRepository.listenForCatFacts().collect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

приложение все еще крашится на старте, если сервис недоступен или нет интернета

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants