When should Operations return a Collection? #107
AlexandruGG
started this conversation in
General
Replies: 3 comments 8 replies
-
@drupol let me know if this makes sense when you have a chance to go over it and think about it |
Beta Was this translation helpful? Give feedback.
3 replies
-
We should categorize 3 types of return:
Do you see something else to add? |
Beta Was this translation helpful? Give feedback.
3 replies
-
Should |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Based on the above I thought I'd start a wider discussion, with the main question: when should operations return a collection object?
Here's what I think: I appreciate the consistency in knowing that a lot of the operations return the same object. There is definitely some benefit to that. However, I think even more important elements can be:
Based on the above, I found a nice little principle that I feel fits quite well. Let me know if it makes sense: operations should return a collection object IF they are meant to be chained. With this I present a couple examples:
Let me know if these things make sense. I can see a few methods which would benefit from having their return type changed, like
contains
,has
,nullsy
,falsy
,truthy
. As a user I think I would expect a simple boolean from all of these.Others which are a bit more debatable would be
first
,get
,head
, where in many cases a user would expect to get the value. Though for these we could argue that you might still want to chain something.Beta Was this translation helpful? Give feedback.
All reactions