Call @enumx macro with NamedTuple constant as input

FireCrumb
Sun, 08 May 2022 08:50:30 +0000
General Usage

Hi, I have a NamedTuple and would like to create an EnumX from it, how can this be done?
CC @fredrikekre

Specifically, I’m using ProtoBuf.il to load an enum from Protocol Buffers.

And I want to create a new type using @enumx macro, where the input to the macro would be the NamedTuple key-value pairs as arguments.

Input:

const SrcProtoBufEnum = (;[
    Symbol("UNIVERSAL") => Int32(0),
    Symbol("WEB") => Int32(1),
    Symbol("IMAGES") => Int32(2),
    Symbol("LOCAL") => Int32(3),
    Symbol("NEWS") => Int32(4),
    Symbol("PRODUCTS") => Int32(5),
    Symbol("VIDEO") => Int32(6),
]...)

Output:

using EnumX
@enumx DstEnumX UNIVERSAL=0 WEB=1 IMAGES=2 LOCAL=3 NEWS=4 PRODUCTS=5 VIDEO=6

2 posts - 2 participants