# Writing a static value-keyed container with dynamic lookup when inlining isn't possible

**URL:** https://discourse.julialang.org/t/writing-a-static-value-keyed-container-with-dynamic-lookup-when-inlining-isnt-possible/135057
**Category:** General Usage
**Created:** [January 14, 2026, 3:32pm UTC](https://discourse.julialang.org/t/writing-a-static-value-keyed-container-with-dynamic-lookup-when-inlining-isnt-possible/135057 "2026-01-14T15:32:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![f.ij](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@f.ij](https://discourse.julialang.org/u/f.ij)
#### Post date: [January 14, 2026, 3:32pm UTC](https://discourse.julialang.org/t/writing-a-static-value-keyed-container-with-dynamic-lookup-when-inlining-isnt-possible/135057/1 "2026-01-14T15:32:18Z")

</div>

Hi all,

I’m experimenting with a container that is conceptually similar to a NamedTuple, except that the “keys” are arbitrary isbits values, not Symbols.

```julia-auto
struct ValueNamedTuple{Vals,K}
    vals::Vals # e.g. tuple of (Val(key) => value) pairs
    dynamic_lookup::Dict{K,Int} # key -> index into vals
end

```

What I would like:

- If the key is known at compile time → use a generated/static lookup (generated linear search and inline the index).
- If the key is only known at runtime → use a single dynamic lookup path (e.g. via the Dict) so that we don’t have to rely on linear search.

e.g.

```julia-auto
@generated function getproperty(vnt::ValueNamedTuple, v::Val{value}) where value
      idx = findfirs(x -> value == x, get_types_of_vals_from_vnt_type(vnt))
      return :(last(getindex(vnt.vals, $idx)))
end

```

but then if the value is not a compile-time constant, just do

```julia-auto
getproperty(vnt::ValueNamedTuple, value) = last(getindex(vnt.values, vnt.dynamic_lookup[value]))

```

where the Dict is filled during construction.

Is this in any way possible?
