andyferris / Dictionaries.jl

An alternative interface for dictionaries in Julia, for improved productivity and performance
Other
278 stars 28 forks source link

Suggestion - getindices!() #119

Open Lincoln-Hannah opened 1 year ago

Lincoln-Hannah commented 1 year ago

what about a function like:

getindices!(d::Dictionary, i::Vector{Symbol}) = filter!( ∈(getindices( d, i )), d )

This implementation only works for unique Dictionary values but it demonstrates the desired functionality.

Could be used to shrink a set of dictionaries to a common set of keys

using Dictionaries, Lazy, Underscores

D1 = Dictionary([:a,:b,:c],[10,11,12])
D2 = Dictionary([:a,:b,:d],[21,22,23])
D3 = Dictionary([:a,:b,:e],[31,32,33])

Common_Indices = @_@>   [D1,D2,D3]   keys.()   intersect(_...)  Indices

getindices!.( [D1,D2,D3]   , [Common_Indices] )
Lincoln-Hannah commented 1 year ago

Or could there be a function Comomn_Indices! or Inner_Join! that takes a Vector of Dictionaries and (as above) converts them all to a common set of keys