-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getfield with integer index argument #4806
Comments
Not sure if this is quite what you had in mind, but it seems pretty trivial to implement for your own type. Or are you asking this be a general feature of types in Base? In [1]: type Foo
a
b
c
d
end
In [2]: importall Base
start(x::Foo) = 1
done(x::Foo, i) = length(names(Foo)) == i-1
next(x::Foo, i) = ((string(names(Foo)[i]),getfield(x,names(Foo)[i])), i+1)
bar = Foo(1,2,3,4)
Out [2]: Foo(1,2,3,4)
In [3]: for x in bar
println(x)
end
("a",1)
("b",2)
("c",3)
("d",4) |
I'm planning to add |
That's exactly what I want, thanks for the update!
|
Woo!
|
Has this been added to the documentation? This sounds like a pretty significant and useful addition. |
Not yet. I think this is still in "banging on the tires" mode, but it should be soon. |
When I want to iterate over all the members of a type the first valid syntax that comes to mind is roughly:
But this might be pretty inefficient (I only looked deep enough to see a call to
collect
, I'm assuming it's creating a new array each time).Maybe this has been discussed before, but wouldn't it be nice if I could:
and count on things in the background to not allocate an array?
The text was updated successfully, but these errors were encountered: