-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
REPLJulia's REPL (Read Eval Print Loop)Julia's REPL (Read Eval Print Loop)completionsTab and autocompletion in the replTab and autocompletion in the replfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requests
Description
I'm faced with a problem that I need to create a new custom type that will inherit from the AbstractVector
, but will also contain the keys
/names
of the corresponding elements, like this:
struct MyType{T} <: AbstractVector{T}
names::Vector{String}
values::Vector{T}
end
Base.size(x::MyType) = size(x.values)
And accordingly, access to elements should be carried out both by indexes and by names:
function Base.getindex(x::MyType, ind...)
return x.values[ind...]
end
function Base.getindex(x::MyType, key::AbstractString)
return x[findall(==(key), x.names)...]
end
And finally, I would like to receive these keys as a hint as a result of auto-completion (TAB
key in REPL):
julia> my_container = MyType{Int64}(["key_1", "key_2"], [1, 2])
julia> my_container["key_<TAB>
"key_1" "key_2"
Is there currently any way to implement this behavior?
I found several threads with almost no answers on this topic:
Metadata
Metadata
Assignees
Labels
REPLJulia's REPL (Read Eval Print Loop)Julia's REPL (Read Eval Print Loop)completionsTab and autocompletion in the replTab and autocompletion in the replfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requests