-
Notifications
You must be signed in to change notification settings - Fork 1
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
Why does indexing a DispatchedTuple
always return a tuple?
#12
Comments
I think so, yes. using DispatchedTuples
struct Foo end;
struct Bar end;
struct Baz end;
tup = (
Pair(Foo(), 1),
Pair(Bar(), 3),
)
dtup = DispatchedSet(tup);
dispatch(dtup, Foo()) # returns 1
dispatch(dtup, Bar()) # returns 3
dispatch(dtup, Baz()) # error
dtup = DispatchedSet(tup, 0);
dispatch(dtup, Foo()) # returns 1
dispatch(dtup, Bar()) # returns 3
dispatch(dtup, Baz()) # returns 0 |
Yeah, probably |
Ah thanks for the clarification. Indeed I guess this suggests that you want to be iterating over the result of indexing a for v in dt[Face()]
# do something with v...
end which will always do the right thing. |
Yes, exactly |
I noticed that indexing a
DispatchedTuple
always returns a tuple:which I thought might introduce lots of
[1]
boilerplate if I used it since I usually want the contents of the 1-tuplebut maybe this is because I'm focusing on the case where each object maps to just one value.
Is it always returning a tuple because you want the type of the output to always be
<:Tuple
? I guess returning[1]
in the case of a 1-tuple might introduce type instability?The text was updated successfully, but these errors were encountered: