Skip to content

Instantly share code, notes, and snippets.

@cesarferreira
Last active May 15, 2021 09:29
Show Gist options
  • Save cesarferreira/3b1e6ff45da2902993a2d934d7898849 to your computer and use it in GitHub Desktop.
Save cesarferreira/3b1e6ff45da2902993a2d934d7898849 to your computer and use it in GitHub Desktop.
class GetFriendsUseCase(
private val friendsRepository: FriendsRepository
) : BaseUseCase<List<User>, GetFriendsUseCase.Params>() {
override suspend fun run(params: Params): Either<Failure, List<User>> {
return try {
val friends = friendsRepository.getFriends(params.maxNumberOfFriends)
Either.Right(friends)
} catch (exp: Exception) {
Either.Left(GetFriendsFailure(exp))
}
}
data class Params(val maxNumberOfFriends: Int)
data class GetFriendsFailure(val error: Exception) : Failure.FeatureFailure(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment