Functional style dictionary and list classes + 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!"
Clean looking reducers:
@pattern(False, any)
def comp_reducer_FA(p1, p2):
return False
@pattern(str, str)
def comp_reducer_SS(p1, p2):
if p1==p2:
return p1
return False
@patterned
def comp_reducer(p1, p2):
'''
Reducer
Check if all strings are equal
'''
def strings_comparator(l):
'''
Returns the common string if all elements of 'l' are equal
else returns False
'''
if len(l)<2:
return False
return reduce(comp_reducer, l)
Tests
=====
Tests can be performed using `nosetests` in the root directory.
========
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!"
Clean looking reducers:
@pattern(False, any)
def comp_reducer_FA(p1, p2):
return False
@pattern(str, str)
def comp_reducer_SS(p1, p2):
if p1==p2:
return p1
return False
@patterned
def comp_reducer(p1, p2):
'''
Reducer
Check if all strings are equal
'''
def strings_comparator(l):
'''
Returns the common string if all elements of 'l' are equal
else returns False
'''
if len(l)<2:
return False
return reduce(comp_reducer, l)
Tests
=====
Tests can be performed using `nosetests` in the root directory.
Project details
Release history Release notifications | RSS feed
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.1.zip
(13.6 kB
view details)
pyfnc-0.1.1.tar.gz
(7.1 kB
view details)
File details
Details for the file pyfnc-0.1.1.zip
.
File metadata
- Download URL: pyfnc-0.1.1.zip
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3b35a96ffdd641a445724711cfe9db9c94d31de4cc23491a3355319176e7dc5 |
|
MD5 | e9ccb9b9fa18d36194381ce90282c840 |
|
BLAKE2b-256 | d8cb20c9610b25c4b5884719f04efaa05085a1dad5fcc72b63420ea37ecb8abb |
File details
Details for the file pyfnc-0.1.1.tar.gz
.
File metadata
- Download URL: pyfnc-0.1.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9deae929af44ff2142ea3faf1599a923e51d741b1495b3f72a74da70b5760916 |
|
MD5 | 0bef584d865a541cf1216fdb357fb7ba |
|
BLAKE2b-256 | 9e2239b7a27e4d21d7098842aa71ce0d5143d6814ed47182a7fcb7bc7109e4c0 |