mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
40 lines
764 B
Python
40 lines
764 B
Python
import functools
|
|
|
|
|
|
def identity(value):
|
|
return value
|
|
|
|
|
|
def combine(f, g):
|
|
return lambda x: f(g(x))
|
|
|
|
|
|
def compose(*functions):
|
|
return functools.reduce(combine, reversed(functions), identity)
|
|
|
|
|
|
def apply_formatters_to_return(*formatters):
|
|
formatter = compose(*formatters)
|
|
|
|
def outer(fn):
|
|
@functools.wraps(fn)
|
|
def inner(*args, **kwargs):
|
|
value = fn(*args, **kwargs)
|
|
return formatter(value)
|
|
return inner
|
|
return outer
|
|
|
|
|
|
def cast_return(_type):
|
|
def outer(fn):
|
|
@functools.wraps(fn)
|
|
def inner(*args, **kwargs):
|
|
return _type(fn(*args, **kwargs))
|
|
|
|
return inner
|
|
return outer
|
|
|
|
|
|
cast_return_to_tuple = cast_return(tuple)
|
|
cast_return_to_dict = cast_return(dict)
|