• Stars
    star
    217
  • Rank 176,426 (Top 4 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pattern matching for python

Patterns Build Status

Pattern matching for python. Works in Python 2.7, 3.3+ and pypy.

Installation

pip install patterns

Usage

from patterns import patterns, Mismatch

@patterns
def factorial():
    if 0: 1
    if n is int: n * factorial(n-1)
    if []: []
    if [x] + xs: [factorial(x)] + factorial(xs)
    if {'n': n, 'f': f}: f(factorial(n))

assert factorial(0) == 1
assert factorial(5) == 120
assert factorial([3,4,2]) == [6, 24, 2]
assert factorial({'n': [5, 1], 'f': sum}) == 121

factorial('hello') # raises Mismatch

See tests for more examples.

TODO

  • docs
  • aliases for structures
  • destructure objects
  • name parameter
  • better handling of Mismatch passing to function env
  • non-strict dict matching

More Repositories

1

funcy

A fancy and practical functional tools
Python
3,248
star
2

django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
Python
2,015
star
3

sublime-reform

A Sublime Text plugin to move through and reform things
Python
179
star
4

whatever

Easy anonymous functions by partial application of operators
Python
99
star
5

handy

Handy django tools
Python
84
star
6

django-pickling

Efficient pickling for django models
Python
73
star
7

pg-bricks

Higher level PostgreSQL client for Node.js
JavaScript
50
star
8

flaws

Finds flaws in your python code
Python
39
star
9

sql-bricks-postgres

Transparent, Schemaless SQL Generation for the PostgreSQL
JavaScript
26
star
10

sublime-hippie-autocomplete

Sublime Text 2/3 style auto completion for ST4
Python
21
star
11

django-easymoney

Easy MoneyField for Django
Python
16
star
12

django-counters

Redis based counters for Django models
Python
15
star
13

CommentsAwareEnter

Smart Enter in line comments in Sublime Text 2/3
Python
15
star
14

djapi

The library of simple helpers to build API with Django.
Python
12
star
15

overload

Overload python 2 functions
Python
10
star
16

aioscrape

Async scraping library
Python
10
star
17

parsechain

Making parsing concise
Python
8
star
18

point-free

Point free async combinators
JavaScript
7
star
19

nesh-history-search

Ctrl-R search for nesh Node.js shell
JavaScript
6
star
20

gzip-reader

Streaming gzip decoder
Python
5
star
21

serverless-docker-artifacts

A Serverless plugin to build your artifacts within docker container
JavaScript
5
star
22

serverless-tesseract

A serverless plugin to add tesseract OCR engine to your artifact
JavaScript
5
star
23

battle-brothers-mods

Mods for Battle Brothers
Squirrel
4
star
24

autolink

Convert URL-like and email-like strings into links
Python
4
star
25

django-dirty

Track dirty fields on django model
Python
4
star
26

postgresql-json

Extract data from PostgreSQL JSON fields.
C
4
star
27

linux-app-logger

An active app/window logger for quantified self purporses
Python
3
star
28

swgoh-tickets-ocr

Recognize SWGOH tickets screenshots
Python
2
star
29

kate-syntax

Modified kate syntax files I used to use
2
star
30

django-union

Unite several querysets into one.
Python
2
star
31

rebind

Rebind hard-coded constants on the fly
Python
2
star
32

sky

A javascript based morph
JavaScript
2
star
33

debug-cache

Cache to speed up debugging
Python
2
star
34

battle-brothers-stdlib

A thing to take the place of lacking/incomplete Squirrel/Battle Brothers standard library
Squirrel
2
star
35

sublime-keylay-replay

A Sublime Text plugin to recover text typed with wrong keyboard layout
Python
1
star
36

aiofilecache

File backend for aiocache
Python
1
star
37

asynx

Async utility extensions
JavaScript
1
star
38

callback-ops

No more "if (err) return callback(err)"
JavaScript
1
star
39

eloquent

Eloquent selection/filter interface
Python
1
star
40

grabber

Web grabber in clojure
Clojure
1
star
41

pytest-matcher

Simplify asserts containing objects and nested data structures
Python
1
star