What do you think of implementing an ItemCollection implements Countable, IteratorAggretate for the use case in your example?
To be honest, i'm not crazy about this Tuple idea. When you return two different things from an interface, you're saying that these values returned together have a special meaning. When using a tuple that meaning is implicit and requires your clients to "just know" why they are returned together. If these values/objects have meaning together, could they be in a single object? This would make the meaning explicit.
Sasa is a highly driven full stack software developer with background in finance and accounting. A relentless problem solver who is passionate about finding elegant solutions to problems at hand.
For the example I used here your suggestion makes perfect sense. You make some valid points, this might not be the best approach if it is going to be publicly exposed, it could be confusing.
Maybe I should have come up with better examples :D
Thank you for reading!
EDIT:
Ok just remember where I used this approach as well:
Hi Sasa, thanks for posting!
What do you think of implementing an
ItemCollection implements Countable, IteratorAggretate
for the use case in your example?To be honest, i'm not crazy about this Tuple idea. When you return two different things from an interface, you're saying that these values returned together have a special meaning. When using a tuple that meaning is implicit and requires your clients to "just know" why they are returned together. If these values/objects have meaning together, could they be in a single object? This would make the meaning explicit.
For the example I used here your suggestion makes perfect sense. You make some valid points, this might not be the best approach if it is going to be publicly exposed, it could be confusing.
Maybe I should have come up with better examples :D
Thank you for reading!
EDIT:
Ok just remember where I used this approach as well:
[$failed, $messages] = $validator->failedWithMessages();
Maybe this example would be better :))