Groovy對於簡單的clojures具有很好的語法,它不需要明確地指定 單個參數。它將被命名爲它默認爲。Groovy的Python模擬器嗎?
def closure = { print it }
closure("hi there") //prints "hi there"
什麼是模擬它 magikal參數在Python中的最佳方式?我想要什麼
例子:
>>> it = It()
>>> print map(it + 5, [1, 2, 3])
[6, 7, 8]
Groovy對於簡單的clojures具有很好的語法,它不需要明確地指定 單個參數。它將被命名爲它默認爲。Groovy的Python模擬器嗎?
def closure = { print it }
closure("hi there") //prints "hi there"
什麼是模擬它 magikal參數在Python中的最佳方式?我想要什麼
例子:
>>> it = It()
>>> print map(it + 5, [1, 2, 3])
[6, 7, 8]
到目前爲止,我已經找到了我的問題確切的anwser。這是實現_ magikal變量和一些可用的函數式編程概念的庫fn.py。使用
例子:
>>> from fn import _
>>> list(map(_ * 2, range(5)))
[0,2,4,6,8]
我的第一個thougt是做一些magikal 它對象與生產curryied功能瑪姬方法。
class It :
def __add__(self, another_one) :
return lambda x: x + another_one
it = It()
print map(it + 5, [1, 2, 3])
那麼,什麼是預期的輸入和輸出? –
不,Python沒有針對lambda函數或函數的隱式「第一個參數」。顯式比隱式更好。 –
@MartijnPieters我當然知道,Python無法做到這一點。我正在尋找一些技巧來做類似的事情。 – uhbif19