mojo
mojo copied to clipboard
[stdlib] Add builtin `any()`/`all()` functions
Adds builtin functions for testing if there are truthy elements in List
, Set
, SIMD
.
Should change to check iterators eventually.
Also mentioned here
Nice, thank you! This will be useful and I can't wait for us to get further along with iterators and algorithms. Do you mind adding a changelog entry here please for this work?
I have another one ready for bitwise reduce_and()
/reduce_or()
, but waiting on this and simd bool constrain to go through .
now i feel like these all should've been done in one go to avoid the intermediate problems, but i guess there's a chance bitwise reduce might not be desired
oh i forgot the changelog entry, hang on
there's a typo in the changelog under the repr()
section, I think by [@mikowals]
should be by [@gabrieldemarmiesse]
i guess we might want all()
of an empty iterator to return True
?
i guess we might want
all()
of an empty iterator to returnTrue
?
I'd say to match the python behavior (I have not checked)
Here are the Python docs for reference:
any:
Return
True
if any element of the iterable is true. If the iterable is empty, returnFalse
.
all:
Return
True
if all elements of the iterable are true (or if the iterable is empty).
✅🟣 This contribution has been merged 🟣✅
Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours.
We use Copybara to merge external contributions, click here to learn more.
Landed in f8a9dd0ab719eb0a6ae2756be5153cdeb6790cc1! Thank you for your contribution 🎉