mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[stdlib] Add builtin `any()`/`all()` functions

Open helehex opened this issue 9 months ago • 8 comments

Adds builtin functions for testing if there are truthy elements in List, Set, SIMD. Should change to check iterators eventually.

Also mentioned here

helehex avatar May 09 '24 16:05 helehex

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?

JoeLoser avatar May 11 '24 15:05 JoeLoser

I have another one ready for bitwise reduce_and()/reduce_or(), but waiting on this and simd bool constrain to go through .

helehex avatar May 13 '24 09:05 helehex

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

helehex avatar May 13 '24 09:05 helehex

oh i forgot the changelog entry, hang on

helehex avatar May 13 '24 09:05 helehex

there's a typo in the changelog under the repr() section, I think by [@mikowals] should be by [@gabrieldemarmiesse]

helehex avatar May 13 '24 09:05 helehex

i guess we might want all() of an empty iterator to return True?

helehex avatar May 15 '24 04:05 helehex

i guess we might want all() of an empty iterator to return True?

I'd say to match the python behavior (I have not checked)

artemiogr97 avatar May 15 '24 05:05 artemiogr97

Here are the Python docs for reference:

any:

Return True if any element of the iterable is true. If the iterable is empty, return False.

all:

Return True if all elements of the iterable are true (or if the iterable is empty).

Brian-M-J avatar May 15 '24 08:05 Brian-M-J

✅🟣 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.

modularbot avatar May 16 '24 02:05 modularbot

Landed in f8a9dd0ab719eb0a6ae2756be5153cdeb6790cc1! Thank you for your contribution 🎉

modularbot avatar May 16 '24 07:05 modularbot