Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install pyfnc

How to install pyfnc

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pyfnc
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1.2 Available View build log
0.1.0 Available View build log
Windows (64-bit)
0.1.2 Available View build log
0.1.0 Available View build log
Mac OS X (10.5+)
0.1.2 Available View build log
0.1.0 Available View build log
Linux (32-bit)
0.1.2 Available View build log
0.1.0 Available View build log
Linux (64-bit)
0.1.2 Available View build log
0.1.0 Available View build log
 
Depended by
Lastest release
version 0.1.2 on Feb 9th, 2012

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):

System Message: ERROR/3 (<string>, line 58)

Unexpected indentation.
return False

@pattern(str, str) def comp_reducer_SS(p1, p2):

System Message: ERROR/3 (<string>, line 62)

Unexpected indentation.
if p1==p2:
return p1

System Message: WARNING/2 (<string>, line 64)

Definition list ends without a blank line; unexpected unindent.

return False

@patterned def comp_reducer(p1, p2):

System Message: ERROR/3 (<string>, line 68)

Unexpected indentation.

''' 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:

System Message: ERROR/3 (<string>, line 81)

Unexpected indentation.
return False

return reduce(comp_reducer, l)

Tests

Tests can be performed using nosetests in the root directory.

Subscribe to package updates

Last updated Feb 9th, 2012

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.