Open Lincoln-Hannah opened 1 year ago
Interesting! Let me go in reverse order:
3 - I love the keyword argument idea! On the reverse side I had been toying with idea of overloading getproperty
to let you fetch Symbol
keys.
2 - Given 3, in recent versions of Julia users could type Dictionary(; struct...)
. Is that right? Given that, should we just document that rather than adding methods that have to infer if something is struct-ish or not?
1 - Is this the same operation as getindices
from Indexing.jl?
For 1, I do think we need to solve this somehow. Sometimes I think about this in terms of tabular data - we have one-one joins, many-one joins and many-many joins. The one-one primary key to primary key join is just merge
. The many-one foreign key to primary key join is like this "compound". I think many-many should generally rely on the user to reindex data - e.g. with group
from SplitApplyCombine.jl or similar (or using innerjoin
from SplitApplyCombine.jl).
3- By overloading getproperty
. Do you mean the ability to write Dict.key instead of Dict[:key] ?
This is what DotMaps.jl does. It works for a Dict
but not a Dictionary
A nice feature to have sometimes.
2 - (; struct...)
Doesn't work on 1.8.0. I use ntfromstruct()
from NamedTupleTools.jl. So maybe could just document to use Dictionary ∘ ntfromstruct
Would be great if it could be done in a Dictionary()
method but I think "struct-ish" can only be determined in the function body (not in the first line where the types are specified.)
1- You're right getindices
does this.
Though getindices( d1, d2 )
fails for any d2
value that not matching a d1
key.
Could there be an option to exclude these and return a Dictionary with keys = intersect( keys(d1), values(d2) )
I really like the relational database analogy. I'm most interested in the PK-FK relationship. I'll add an example.
using WhereTraits, NamedTupleTools
@traits Dictionary( x ) where isstructtype(typeof(x)) = Dictionary( ntfromstruct( x ))
Could do this