Skip to main content

Python decorators for pattern matching function dispatch

Project description

Overview

Functional style ‘list’ and ‘dict’ classes & decorators for pattern matching function dispatch.

For more information, visit http://www.systemical.com/doc/opensource/pyfnc

Examples

Dictionary class ‘dic’ with ‘return self’ functionality:

>>> d=dic({"k2":"v2"})
>>> dr=d.update({"k1":"v1"})
>>> self.assertEqual(d, dr)

List class ‘liste’ with ‘return self’ functionality and integrated ‘map’, ‘reduce’ and ‘filter’ functions:

>>> l=liste()
>>> lr=l.extend([1,2,3])
>>> self.assertEqual(len(l), 3)
>>> self.assertEqual(l, lr)
>>> f=lambda x:x+10
>>> lm=l.map(f)
>>> self.assertEqual(lm, [11, 12, 13])
>>> self.assertEqual(l, [11, 12, 13])

Erlang style function dispatch:

>>> @pattern('male', str)
... def greet_male(p1, p2):
...     return "Hello M. %s!" % p2
>>> @pattern('female', str)
... def greet_female(p1, p2):
...        return "Hello Mrs. %s!" % p2
>>> @patterned
... def greet(p1, p2):
...    pass
>>> print greet("male", "Dupont")
"Hello M. Dupont!"
>>> print greet("female", "Corriveau")
"Hello Mrs. Corriveau!"

Tests

Tests can be performed using nosetests in the root directory.

Project details


Download files

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

Source Distributions

pyfnc-0.1.0.zip (11.5 kB view details)

Uploaded Source

pyfnc-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file pyfnc-0.1.0.zip.

File metadata

  • Download URL: pyfnc-0.1.0.zip
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyfnc-0.1.0.zip
Algorithm Hash digest
SHA256 0bd284ba1f4a9468cae11e76fdf9ae2fc987189dcd14e8d2ec72e37cee04e744
MD5 96895891f207e6abd396e3b4f13d12ea
BLAKE2b-256 c0d69aec61b4b850e9a89a34f901047bfac288dfe02067b0a2656b5af4bcf7ff

See more details on using hashes here.

File details

Details for the file pyfnc-0.1.0.tar.gz.

File metadata

  • Download URL: pyfnc-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyfnc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c8bdacce208859c8c0874458689c4eae0a1b62acc5ca79710ac75b4aea98fc39
MD5 5fd4db01c02c5516ec82a47096f01f6f
BLAKE2b-256 1afa46f9185a86ff4f173df35781de35b5087924871200b1ef9122bbe7fe4e02

See more details on using hashes here.

Supported by

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