Я пытаюсь перенести некоторые js на python, и у меня возникают проблемы с использованием python лямбда-функций. Мой JS выглядит следующим образом:
function wrapFunc(otherFunc) {
return (value) => {
index = otherFunc(bytes, index, value);
return index;
}
}
number =>
wrapFunc(
(bytes, index) => someFunc(bytes, index, number)
)()
//returns a function and executes it. number is captured as value in first snippet.
Я пытаюсь добиться того же в python, используя лямбды, но не могу захватить число для использования в otherFun c
Вот мой python:
def wrapFunc(otherFunc):
def func2(value): //how do I capture outer lamba value?
index = otherFunc(bbytes,index,value)
return index
return func2(otherFunc) //lambda passed in here
lambda number: wrapFunc(lambda b,i,number:self.someFunc(b,i, number))
//how do I capture the value of number inside wrapFunc?
Мои вопросы: Правильно ли написано мое лямбда-определение по сравнению с js равнозначным? Как мне зафиксировать значение числа внутри wrapFun c? Должен ли я использовать другой подход, портируя этот кусок JS