-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include a @list->contains('element') method? #267
Comments
You can currently do that with I can think of a few things to be done which would make things better.
The above is a general improvement to all the list searching methods.
If you'd like to do this yourself, it's normal Perl. You can ignore the autobox magic. |
I understand that you're leaving me the choice. |
Rather than using first, why not count? @ingredients->count(0) or @ingredients->count('') returns a true value if the (false) element is contained in the array. |
Because count() will iterate over the whole list, while first() will stop as soon as it finds the element. I prefer any() over first(). It will do exactly the same things, but i find it expresses the intent better: |
This is the clearest way that i've found to indicate that a list contains a given element:
use syntax 'junction';
use autobox;
sub ARRAY::contains { any( @{$[0]} ) eq $[1] };
@ingredients->contains('flour')
that's just a humble proposal
The text was updated successfully, but these errors were encountered: