Reputation: 15385
Let's say I have to develop an API which will talk to the database and will have some methods to do CRUD operations. Let's say I have a method that fetches a List of something based on some criteria:
def fetchUsers(criteria: Criteria): List[User] = ???
If I cannot find any users for the given Criteria, should I return an empty List or it is a good practice to return a Try[List[User]] and if I do not find any users, I return a Failure?
What is considered a good practice?
Upvotes: 0
Views: 199
Reputation: 7735
This question does not have a definite answer, it depends on your preferences and your API requirements.
All solutions are acceptable and depend on requirement.
I personally would prefer 1st or 2nd solutions, because
Upvotes: 1