This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

switchcase implements a simple Switch-Case construct in Pure Python.

Under the hood, the switch function works by simply returning a length-1 list containing a matching function. The entire implementation is 3 lines long:

from operator import eq
def switch(value, comp=eq):
    return [lambda match: comp(match, value)]

Basic Usage

>>> from switchcase import switch
>>> def func(x):
...     for case in switch(x):
...         if case(0):
...             print("x was 0")
...             break
...         if case(1):
...             print("x was 1")
...             break
...     else:
...         print("x was unmatched")
>>> func(0)
"x was 0"
>>> func(1)
"x was 1"
>>> func(2)
"x was unmatched"

Custom Comparisons

By default, switch uses operator.eq to compare the value passed to switch and the values subsequently passed to case. You can override this behavior by passing a comparator function to switch as a second argument.

>>> import re
>>> from switchcase import switch
>>> def f(x):
...     out = []
...     for case in switch(x, comp=re.match):
...         if case("foo_bar"):
...             out.append(0)
...             break
...         if case("foo_.*"):
...             out.append(1)
...         if case(".*_bar"):
...             out.append(2)
...         return out
>>> f("foo_bar")
[0]
>>> f("foo_notbar")
[1]
>>> f("notfoo_bar")
[2]
>>> f("foo____bar")
[1, 2]
Release History

Release History

1.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
switchcase-1.0.tar.gz (2.2 kB) Copy SHA256 Checksum SHA256 Source Aug 18, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting