Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Created September 14, 2021 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbedoy/0b3f8b5213d5c1ba23d68aee5906157e to your computer and use it in GitHub Desktop.
Save cbedoy/0b3f8b5213d5c1ba23d68aee5906157e to your computer and use it in GitHub Desktop.
Fancy use Case and viewModel
class FancyUseCase (private val serviceOrAnyDataLayer: Something){
operator fun invoke(number: String) = flow {
when(val response = serviceOrAnyDataLayer.requestAny()) {
is Success -> {
emit("Yeah")
}
else -> {
emit("Damit")
}
}
}
}
class ViewModel (useCase: FancyUseCase) : MVIVM<YourIntent, YourState>{
override fun handle(intent: YourIntent) {
producer(useCase(intent.anyPropMaybe))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment