On Monday, October 12, 2015 at 8:20:52 PM UTC-4, Chris wrote:
>
> Sorry for the awkward wording. Here's an example:
>
> julia> type MyType
>        x::Float64
>        end
>
> julia> v = [MyType(float(i)) for i in 1:50];
>
> My question is: how do I best recover the values of x for all elements in 
> v. Here's the way I do it now:
>
> julia> u = [v[i].x for i in 1:50]
>
> This has the unfortunate effect of giving me an Array{Any,1}, 
>

Float64[vv.x for vv in v]

will give you the type you want.  However, if you do [vv.x for vv in v] in 
a function, instead of in global scope (where Julia can't always do type 
inference), it will automatically be Float64.

Reply via email to