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

ДЗ HomeWork flow - Sergey Kudashkin #65

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

Conversation

mobilesikuda
Copy link

No description provided.


init {
viewModelScope.launch {
withContext(Dispatchers.IO) {
withContext(Dispatchers.Main) {

Choose a reason for hiding this comment

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

нет нужды, viewmodelscope работает на main диспачере

@@ -14,8 +19,23 @@ class MainActivity : AppCompatActivity() {
val view = layoutInflater.inflate(R.layout.activity_main, null) as CatsView
setContentView(view)

catsViewModel.catsLiveData.observe(this){
view.populate(it)
// catsViewModel.catsLiveData.observe(this){

Choose a reason for hiding this comment

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

неиспользуемый код можно почистить, оставлять за собой порядок - хорошоу

return flow {
sampleRepository.produceNumbers().collect {
emit(it.toString())
if(it % 15 == 0) emit("FizzBuzz")

Choose a reason for hiding this comment

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

Это можно преобразовать в when, чтобы не было такой вложенности if-else

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

return flow {

Choose a reason for hiding this comment

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

тут можно сделать немного элегантнее - sampleRepository.produceNumbers() возвращает flow, поэтому нам не нужно создавать новый flow. после вызова produceNumbers() можно посмотреть в сторону функций Flow.catch и Flow.onCompletion, они покроют 100% требований задачи

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.

3 participants