[Python-ideas] custom predicate for all() & any()

titouan dk dk.titouan at gmail.com
Sat Mar 26 12:30:19 EDT 2016


Hi,

I was wondering if the builtins functions all() & any() could ever accept a
custom predicate:

    all(iterable, predicate=bool)
    any(iterable, predicate=bool)

Something like Lodash.js functions: every(), ...

## Example 1

    ages = [21, 13, 18]
    major = 18..__le__

    allowed = all(ages, major)

## Example 2

    people = [
        {"name": "Mike", "age": 42},
        {"name": "Josh", "age": 17}
    ]
    major = 18..__le__

    allowed = all(people, {"age": major})

## Consistency drawbacks

The filter() function takes its arguments in the reverse order:

    filter(predicate_or_none, iterable)

I would have write this function like this...

    filter(iterable, predicate=None)

... but this is not the case, anyway.

## Your opinion?

What do you think about this?
Good idea, could be a quick-win?
Or requiring a lot of efforts for nothing?
What about consistency drawbacks?


Thanks for reading,

Titouan de Kerautem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160326/2b3352a9/attachment.html>


More information about the Python-ideas mailing list