muu

a decorator providing multiline lambdas for Python3


Keywords
decorator, lambda
License
Other
Install
pip install muu

Documentation

#muu

a decorator providing multiline lambdas for Python3

@muu
def wat(x):
	return map(lam(e)[
		print(e),
		len(e)], x)

wat(['a', 'hello']) # print e and hello, 
# [1, 5]

it supports assignment with <-, because there was no way to do it with = (lam(e)(x, e = x) syntax was considered, but it wouldn't work for lam()(e=2, e) cases)

from muu import muu

@muu
def ok(x):
	return map(lam(e)[
		x['name'] <- "ha",
		x], x)

ok([{'name': 2}]) # [{'name': 'ha'}]

##implementation

a decorator which patches bytecode of decorated function: replaces lam macro invocations with bytecode for an equivalent lambda (the limitation for one expression is only on language/ast level, not in the VM)

dark magic, a horrible hack, but really a lot of fun

install

pip install muu

thanks

uses a forked and patched version of byteplay. Credits to https://wiki.python.org/moin/ByteplayDoc and https://github.com/serprex/byteplay