Welcome to funky’s documentation!

Contents:

Tiny functional programming oriented Python library inspired by underscore.js and Haskell prelude.

funky.compose(f1, f2, *fs)

Takes a two or more functions and returns a composition of them:

>>> fn = compose(lambda x: x/2, lambda x: x+5)
>>> fn(5)

5.0

funky.curry(fn)

Returns a function that can be partially applied:

>>> fn = curry(lambda x,y: x**y)
>>> fn(2,8)

256 >>> fn(2)(8) 256

funky.template(f, *args, **kwargs)

Returns a function with some of its arguments bound:

>>> fn = template(lambda a,b,c: (a*b)/c, ___, 2, ___)
>>> fn(5, 2)

5.0

class funky.chain

A subclass of list that changes the behaviour of append, extend, insert, remove, reverse and sort so that they allow chaining of method calls:

>>> chain([1,2,3]).append(4).reverse().extend([5, 6]).sort()
[1,2,3,4,5,6]
funky.caller(method, *args, **kwargs)

Returns a function that takes an object and calls its method optionally passing it *args and **kwargs

funky.invoke(iterable, method, *args, **kwargs)

Invokes method on every member of the iterable passing it *args and **kwargs

funky.iterate(fn, x)

An iterator that repeatedly applies fn to x

funky.pre(*checks)

A decorator that checks that all of the provided preconditions are met when the function is called:

>>> @pre(lambda x: x > 0)
>>> def fn(x):
>>>     return x*x
>>> fn(-1)
funky.post(*checks)

A decorator that checks that all of the provided postconditions are met when the function returns

funky.identity(arg)

A function that takes one argument and returns it.

funky.flip(fn)

A function that takes a function with arity of two and returns a function with the arguments flipped

funky.first(xs)

Takes an iterable and returns its first item

funky.second(xs)

Takes and iterable and returns its second item

exception funky.ConditionError

Raised when pre- or postcondition fails

Indices and tables

Project Versions

Table Of Contents

This Page