Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Functional Pattern Matching for Python

Project Description

Splarnektity provides a limited, but valuable, form of functional pattern matching to Python, a la OCaml, Erlang, Haskell, et al.. Another way of thinking of this is: pattern matching over Python lists.

Here is a quick example of Splarnektity’s usage:

from splarnektity import FMatch

sexpr = ('person',
            ('name', 'john'),
            ('address', ('line1', '123 Townville'), ('zip', 54321)),
            ('age', 24),
            ('favorite foods', 'pizza', 'dorritos'),
        )

for x in sexpr[1:]:
    f = FMatch(x)
    V1, V2 = f.var(2)
    if f.when(('name', V1)):
        print 'name:          ', V1.v
    elif f.when(('address', ('line1', V1), ('zip', V2))) and V2.int:
        print 'address line1: ', V1.v
        print 'address zip:   ', V2.v
    elif f.when(('age', V1)) and V1.int:
        print 'age:           ', V1.v
    elif f.when(('favorite foods', V1.others)): # variable length matching
        print 'favorite foods:', V1.v

The result of this example is:

name:           john
address line1:  123 Townville
address zip:    54321
age:            24
favorite foods: ('pizza', 'dorritos')
Release History

Release History

This version
History Node

0.3

History Node

0.2

History Node

0.1

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS 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