> On 4 Apr 2017, at 11:31, Trey Ethan Harris wrote:
>
> I'm thinking of a Hash-like collection where I can add objects using a
> index-less append operation, but then have random access to the elements
> based on a key provided by the object. (For instance, imagine a ProcessTable,
> where I create the collection telling it to index by the .pid method, add
> each process to %table in serial without mentioning pid, and then look up the
> one referring to the interpreter with %table{$*PID}.)
This is basically the approach that object hashes take internally. So, feels
to me you just need object hashes?
https://docs.perl6.org/type/Hash#index-entry-object_hash
Objects are internally keyed to the result of the .WHICH method on that object.
If you create a class, one will be provided for you automatically. But
there’s nothing preventing you from making your own .WHICH method, as long as
the result is consistent for a given object and the same for all objects you
think should be considered identical, you should be fine.
> I really thought this was in Perl 6, but I can't find it in the docs, so
> maybe I'm thinking of another language. (I think both Ruby and Python have
> adverbial-like options to do things like this with dictionaries, so maybe
> that's what I'm thinking of.) Or maybe it's a simple tweak to an existing
> collection, or just something I need to implement in my element objects
If this is not what you’re looking for, perhaps you can elaborate a bit more,
with some code examples?
Liz