Closed jim108dev closed 2 years ago
The generator is not the problem. The problem is that your transform function takes two arguments. So you need to star the tuple argument:
ys = pipe(get_train_test_years(), seq.map(lambda x: transform(*x)))
But we should probably just add a starmap
operator to the seq
module:
def starmap(
mapper: Callable[[Tuple[Any, ...]], Any]
) -> Callable[[Iterable[Any]], Iterable[Any]]:
return seq.map(lambda x: mapper(*x))
At
ys = pipe(get_train_test_years(), seq.map(lambda x: transform(*x)))
I get
(parameter) x: TSource@map "object*" is not iterable "__iter__" method not definedPylance
Yes, lambdas do not support type annotations. Use a function instead so you can specify the type of x
e.g:
def mapper(x: Tuple[List[int], int]):
return transform(*x)
ys = pipe(get_train_test_years(), seq.map(mapper))
PS: Also add type annotations to transform
.
Thanks for explaining this to me.
Hi!
Is there a way to map over generators? Can
seq
help? For example:Thanks!