0

The Code A is from the artical .

I think Code A can be converted to Code B, is it correct?

Code A

class MainViewModel {
    val repositoryResult = Transformations.switchMap(userManager.user) { user ->
        repository.getDataForUser(user)
  }
}

Code B

class MainViewModel {
    val repositoryResult = Transformations.map(userManager.user){ user->
       repository.getDataForUser(user) 
  }
}

original Image enter image description here

HelloCW
  • 476
  • 10
  • 77
  • 178
  • Although there are some differences, but in your case both are same and you can use any – Pankaj Kumar Aug 25 '20 at 02:30
  • There is detailed answer https://stackoverflow.com/questions/47575961/what-is-the-difference-between-map-and-switchmap-methods – rost Aug 25 '20 at 04:25

0 Answers0