Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Enhance filters to search for no-particular-object and non-empty-collection #144

Open
idanarye opened this issue Jan 6, 2019 · 0 comments

Comments

@idanarye
Copy link

idanarye commented Jan 6, 2019

from easypy.tokens import ANY

some_collection.filtered(foo=ANY)

should be equivalent to:

def pred(obj):
    try:
        return bool(obj.foo)
    except LookupError:
        return False

So:

  • If foo is a single object, some_collection.filtered(foo=ANY) should return all objects that have a foo (which is not None, and where obj.foo doesn't throw)
  • If foo is a collection, some_collection.filtered(foo=ANY) should return all objects that have a non-empty foo.

Open Question

Do we need a NONE token, which is the reverse of ANY? We can usually do some_collection.filtered(foo=[]) or some_collection.filtered(foo=None), depending on the situation, but some_collection.filtered(foo=None) will support cases where obj.foo throws, and will also be a more uniform way to do this search.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant