Just in case it seems a bit more transparent, this also works:

r = rand(5)
map( x -> x[1] + x[2], enumerate(r))



El martes, 14 de julio de 2015, 20:20:14 (UTC-5), Yichao Yu escribió:
>
> On Tue, Jul 14, 2015 at 7:09 PM, Ritchie Lee <[email protected] 
> <javascript:>> wrote: 
> > Sorry if this is a newbie question.  I am trying to get map() to work 
> with 
> > with enumerate() but I am getting an error. 
> > 
> > r=rand(5) 
> > map((i,v)->i+v, enumerate(r)) 
> > ERROR: wrong number of arguments 
> >  in anonymous at none:1 
> >  in map at abstractarray.jl:1207 
> > 
> > collect(enumerate(r)) generates an array of 2-tuples as expected. 
>
> `map` does not splat each element of the iteration and only pass each 
> element as a single argument to the function 
>
> ```julia 
> julia> r = rand(5) 
>       map(x->((i, v) = x; i + v), enumerate(r)) 
> 5-element Array{Any,1}: 
> 1.6277 
> 2.41751 
> 3.34848 
> 4.70194 
> 5.89139 
>
> ``` 
>
> > 
> > Is the syntax incorrect? 
> > 
> > Thanks, 
> > 
> > Ritchie 
>

Reply via email to