3 ms·
Seems like you can write code in this style, if that's the style you like, without the magical and error-prone stack/environment inspection. Like, this example:
by abecedarius 17y ago
Seems like you can write code in this style, if that's the style you like, without the magical and error-prone stack/environment inspection. Like, this example:
with bmap([1,2,3]) as foo:
def _(x):
return (float(x) + 1) / 2
print foo # [1.0, 1.5, 2.0]
could be done with decorators:
def flip(f, x): # from Haskell's standard library
return lambda y: f(y, x)
@flip(map, [1,2,3])
def result(x):
return (float(x) + 1) / 2
print result # [1.0, 1.5, 2.0]
though the way 'result' is bound is, er, unconventional.