Functional

This module provides functions known from functional programming languages.

brownie.functional.compose(*functions)[source]

Returns a function which acts as a composition of several functions. If one function is given it is returned if no function is given a TypeError is raised.

>>> from brownie.functional import compose
>>> compose(lambda x: x + 1, lambda x: x * 2)(1)
3

Note

Each function (except the last one) has to take the result of the last function as argument.

brownie.functional.flip(function)[source]

Returns a function which behaves like function but gets the given positional arguments reversed; keyword arguments are passed through.

>>> from brownie.functional import flip
>>> def f(a, b): return a
>>> f(1, 2)
1
>>> flip(f)(1, 2)
2
class brownie.functional.Signature[source]

A named tuple representing a function signature.

Parameters:
  • positionals – A list of required positional parameters.
  • kwparams – A list containing the keyword arguments, each as a tuple containing the name and default value, in order of their appearance in the function definition.
  • varargs – The name used for arbitrary positional arguments or None.
  • varkwargs – The name used for arbitary keyword arguments or None.

Warning

The size of Signature tuples may change in the future to accommodate additional information like annotations. Therefore you should not rely on it.

New in version 0.5.

classmethod from_function(func)[source]

Constructs a Signature from the given function or method.

bind_arguments(args=(), kwargs=None)[source]

Returns a dictionary with the names of the parameters as keys with their arguments as values.

Raises a ValueError if there are too many args and/or kwargs that are missing or repeated.

class brownie.functional.curried(function)[source]

curried is a decorator providing currying for callable objects.

Each call to the curried callable returns a new curried object unless it is called with every argument required for a ‘successful’ call to the function:

>>> foo = curried(lambda a, b, c: a + b * c)
>>> foo(1, 2, 3)
6
>>> bar = foo(c=2)
>>> bar(2, 3)
8
>>> baz = bar(3)
>>> baz(3)
9

By the way if the function takes arbitrary positional and/or keyword arguments this will work as expected.

New in version 0.5.

Navigation

Documentation overview

This Page

Fork me on GitHub