These are chat archives for evhub/coconut

20th
Mar 2018
Vikram Kalabi
@vikramkalabi
Mar 20 2018 09:44

Hi, I just started using coconut and I have a very trivial question. How does one pass positional arguments to a map function?

When I run below code in jupyter lab I get TypeError: <lambda>() missing 1 required positional argument: 'v'

%%coconut
[(1, 2), (3, 4)] |> map$((k, v)-> (k, v**2)) |> list

But this runs fine.

%%coconut
[(1, 2), (3, 4)] |> map$(v-> (v[0], v[-1]**2)) |> list
Elliott Indiran
@eindiran
Mar 20 2018 18:55
change map to starmap
[(1, 2), (3, 4)] |> starmap$((k, v)-> (k, v**2)) |> list
Evan Hubinger
@evhub
Mar 20 2018 18:58
@vikramkalabi If you use @eindiran's answer it should work, or if you want pattern-matching support in your lambdas you can do
[(1, 2), (3, 4)] |> map$(def ([k, v]) -> (k, v**2)) |> list