-
Notifications
You must be signed in to change notification settings - Fork 195
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
base: master
Are you sure you want to change the base?
Flow Homework #68
Conversation
.transform { number -> | ||
when { | ||
number % 15 == 0 -> { | ||
emit(number.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emit(number.toString()) можно вынести за when, чтобы не писать его три раза
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если флоу produceNumbers() завершится без ошибки, то условие задачи не выполнится (sampleRepository.completed() не будет вызван)
There was a problem hiding this comment.
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)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно использовать map тут и тремя строчками ниже, он попроще выглядит чем transform
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
приложение все еще крашится на старте, если сервис недоступен или нет интернета
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поправил
No description provided.