Skip to main content

A framework for creating complex if statements.

Project description

ifcollector

A framework for creating complex if statements.

pip3 install ifcollector

How to

With ifcollector, if statements can be created from lists. For complex if statements, stating all your conditionals in a list has the advantage of making code more readable and reuseable.

To use it, create a list with all the conditionals that will be evaluated against a single value. The conditionals can be a function, a boolean expression in the form of a string, or a lambda. For all boolean expressions and lamdas, the keyword value will be used for the variable being evaluated.

def matches_email_regex(value):
    match_object = search(r'^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$',
                          value)
    return bool(match_object)

is_valid_gmail = [
    "len(value) > 5",
    "'@' in value",
    matches_email_regex,
    "'gmail.com' in value"
]

my_email = "jeff.gruenbaum@gmail.com"

if ifandstatement(my_email, *is_valid_gmail):
    print("The email is valid!")

Output: The email is valid!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ifcollector-0.0.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

ifcollector-0.0.1-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page