Questions tagged [enums]

A data type consisting of a set of named values called elements, members or enumerators of the type.

Filter by
Sorted by
Tagged with
0 votes
0 answers
15 views

Using TS generic parameter default value for React component prop breaks autocomplete for this prop

There is a Button component with an s | m size and m by default. There are different icon components, each has from one to four sizes of xs | s | m | l, no default. Button takes an icon component as a ...
keann's user avatar
  • 1
1 vote
0 answers
35 views

Unexpected results using "in" with an Enum

The following program (checked on Python 3.9 and 3.10) outputs False, but I expected it to output True: import enum class OtherTest(str, enum.Enum): CLIP = "clip" class Test(str, ...
Jason C's user avatar
  • 38.7k
0 votes
0 answers
31 views

Check if string is a number with Rust match statement [duplicate]

I am implementing a parser in Rust. I have a match statement that will turn parts of a string into tokens. I have enum values for each of the functions that I hope to pull out of the string, and an ...
tclemment's user avatar
0 votes
1 answer
56 views

What is this syntax of wrapping an enum type in parentheses?

There's this really weird syntax that I don't understand. On the libcurl site documentation there's an enum defined as: typedef enum { CURLSSLBACKEND_NONE = 0, CURLSSLBACKEND_OPENSSL = 1, /* or ...
Zebrafish's user avatar
  • 11.8k
2 votes
2 answers
36 views

How do I detect if a value is an enum instance in Kotlin?

Here is my first try: enum class Color { R, G, B} fun main() { val x: Any = Color.R println(x::class.isInstance(Enum::class)) } it prints false :-( when I expect it to return true.
david.perez's user avatar
  • 6,164
0 votes
0 answers
35 views

What Peoplecode syntax is required to pass an enum constant to a class method of a java object using reflection?

I am using the Apache POI class SXSSFWorkbook through Peoplecode to write large amounts of data to an excel file. I know very little Java but was able to put together code which produces the file ...
Veteris Schola's user avatar
-1 votes
0 answers
21 views

printing java enum class [closed]

import java.util.Scanner; public class ClassifyMessage { enum MessageCategory {NEED, OFFER, ALERT, INFO, UNKNOWN} public static void main(String[] args) { Scanner sc = new ...
shortforestboy's user avatar
0 votes
0 answers
22 views

ASP.NET Core Serialize all Enums to UpperCase

I have enum in ASP.NET application. e.g.: public enum Status { Active, Inactive, Offline } I want to return these Enum values as UpperCase in API ...
Dunnoman's user avatar
-1 votes
0 answers
23 views

Is there a way in SystemVerilog to directly cast the output of a module to the desired type without an intermediate variable?

Essentially I was trying to figure out a way that I don't have to use this clumsy workaround in my RTL to get it to compile cleanly. After trying several fruitless ways of searching for the answer, I ...
fnJeff's user avatar
  • 29
0 votes
2 answers
29 views

MongoDb - Spring Boot - Enum Type

I have a project with Spring Boot and MongoDB. I have an enum class that return Integer. But, as far as i know, enum types saved as String into mongdb. But, i want to saved as Integer. How can i ...
fsk's user avatar
  • 219
1 vote
1 answer
24 views

Streamlining Enum Type Identification with PostgreSQL Comments in Ruby on Rails

I'm using Ruby on Rails and currently facing a challenge when trying to discern the meaning of numeric values representing enum types within a PostgreSQL column. To illustrate, I have a stage column ...
dontStayHere's user avatar
0 votes
0 answers
17 views

In Spring Boot 2.5, how do I convert an enum with a String value to my @RequestParam?

I'm using Spring Boot 2.5. I have this enum public enum MyEnum { VALUE1("Label 1"), VALUE2("Label 2"), VALUE3("Label 3"); private String label; ...
Dave's user avatar
  • 16k
0 votes
1 answer
27 views

Using isinstance with StrEnum

I'm using a similiar setup to the toy example provided below in a unit test where I'm trying to ensure the types in my TypedDict named AnimalInfo are correct. ### types.py from typing import ...
harryjulian's user avatar
-1 votes
0 answers
37 views

Return Enum value rather that text after Deserialization

There is property in class public HttpStatusCode StatusCode { get; set; } Whenever deserialization happens value of the Enum should go rather that text Like incase of HttpStatusCode.Ok , OK is going ...
Sheo Kumar Pandey's user avatar
1 vote
2 answers
247 views

How can i fix warning that Class 'Shape' is exposed outside its defined visibility scope? (JAVA 17)

I made function 'warn' in line 17 whose parameter is enum Shape. Why warning about visibility scope and how can I fix it? import java.util.Scanner; public class AreaCalculator { enum Shape {...
hong's user avatar
  • 23
0 votes
2 answers
24 views

Exhaustive groupBy for enum keys

I would like to group a list to a Map that contains every single key of an enum class. Consider the following example: enum class E { A, B, C } fun main() { val l = listOf("Alice", &...
k314159's user avatar
  • 5,141
0 votes
1 answer
52 views

Create string enum from IntEnum

I have an IntEnum like this class TransactionTypeIntEnum(IntEnum): UNKNOWN = 0 ADMINISTRATIVE = 1 PAYMENT = 2 TRADE = 3 I want to create a string enum that has the same names of the ...
Henrique Andrade's user avatar
-4 votes
0 answers
35 views

java.util.ImmutableCollections$List12 cannot be cast to class java.lang.Enum [closed]

After migrating to Spring Boot 3 I have this error : java.lang.ClassCastException: class java.util.ImmutableCollections$List12 cannot be cast to class java.lang.Enum (java.util.ImmutableCollections$...
hermi wael's user avatar
0 votes
3 answers
53 views

Operator '==' cannot be applied to 'Byte' and 'Type'

Having this: enum class Type(val value: Byte){ TOP(0), BOTTOM(1); } and this: val position: Byte = binaryReader.readByte() this line, gives error: if (position == BarElement.Type.BOTTOM) ...
NullPointerException's user avatar
3 votes
3 answers
75 views

Use of an overloaded operator in a scoped enum definition

Given this code #include <iostream> #include <format> enum class Enum; constexpr Enum operator~(Enum) { return static_cast<Enum>(5); } enum class Enum { A = 1, B = ~Enum::A }; // ...
Kane's user avatar
  • 5,675
1 vote
1 answer
41 views

How to create a Mixin Enum

I'm trying to create an enum with a pathlib.Path mixin, MCVE: import enum, pathlib class Test(pathlib.Path, enum.Enum): path1 = pathlib.Path('/path1') path2 = pathlib.Path('/path2') which ...
alex's user avatar
  • 11k
1 vote
1 answer
39 views

Why can't I return self in this Swift indirect enum?

Why can't I return self at the indicated point? indirect enum BinarySearchTree<E: Comparable> { case leaf case node(BinarySearchTree<E>, E, BinarySearchTree<E>) mutating ...
Jeff's user avatar
  • 33
0 votes
1 answer
45 views

Get cross product of two enums in Rust without Typing them all out

Say for example we have two enums that represent the Rank and Suit of a deck of standard playing cards: #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] enum Suit { Spades, Hearts, ...
Jared Smith's user avatar
  • 19.9k
1 vote
1 answer
30 views

Uses different Enum in different inherited class

I have two classes inherited from a base class, is it possible to use different enum on their respective class? public abstract class BaseClass { public enum BaseEnum {a,b,c} public void ...
Wei Bin's user avatar
  • 31
0 votes
1 answer
28 views

T::Enum raises uninitialized constant if invalid enum used instead of raising error of invalid enum used for type

In our app we use an Enum for variant on our button component: class ButtonComponent sig do params( button_variant: ButtonVariant ).void end def initialize(button_variant: ...
Cameron's user avatar
  • 28k
0 votes
2 answers
59 views

Reference/pointer to array of enums not getting the right valu

I have an array of enums: typedef enum { Item0, Item1, Item2 } ITEMS_TYPE; ITEMS_TYPE MyItemsArray[] = { Item0, Item1, Item2 }; bool findIndexOfItemInArray(int32_t ...
Arni's user avatar
  • 21
1 vote
1 answer
63 views

How do I always return the value from an enum as a string

I am using Python 3.9.6. I am trying to write more readable code by using enums. The enums are being used for REST API output. In the example below the output from the enum MUST be a string and ...
Keith's user avatar
  • 4,149
0 votes
1 answer
43 views

An argument that can be a combination of enum.IntFlag

Given an enum.IntFlag: class Flag(enum.IntFlag): FOO = 1 BAR = 2 QUX = 4 Can I express a type that says "Flag or any combination of Flags"? def func(accepts: CombinationOf[Flag])...
scravy's user avatar
  • 11.9k
1 vote
1 answer
27 views

Nestjs Override property in child class dto nodejs

I have staus enum like this export enum Status { Active = "Active", Inactive = "Inactive", } and i have UserStatus like this export enum UserStatus { Active = Status.Active, ...
Sunil Garg's user avatar
  • 14.7k
0 votes
0 answers
22 views

enum export in types.d.ts file drop error

I use NextJS and I want export enum in types.d.ts. I get Module not found: Can't resolve '@/types'. Other exports works properly. My tsconfig.json is: { "compilerOptions": { "...
Papp Zoltán's user avatar
0 votes
1 answer
25 views

Use TypeScript enum instead of union for object keys

I have this mapping in my React typescript project: const templates = { TypeOne: { expanded: (typeOne: ItemOneType) => <ItemOne key={typeOne.id} {...typeOne} />, }, TypeTwo: ...
meez's user avatar
  • 3,843
1 vote
1 answer
28 views

Pre-built class variables in Enum subclass

I'm making a set of Enum classes, and I'd like to build a few iterables over the Enum members up front. Ideally these iterables would be accessible in O(1) time (after the initial build) via a class ...
obviouslyalive's user avatar
0 votes
1 answer
66 views

Using `match` together with a nested `enum` in Rust

Suppose I'm having an enum with some kind of nested structure. Is there a way to model this such that the Rust compiler can provide useful checks when using match while avoiding verbose match ...
RikH's user avatar
  • 3,006
1 vote
2 answers
40 views

Finding the average value of a list through an enum in python

For a school project I need to find the average value of a list through its elements. However these elements are not regular integers and part of an Enum. An example here : My plan is to add the name ...
Daan Van de Wiel's user avatar
0 votes
0 answers
25 views

Typescript enum forces invalid require() in common js

file.ts: import { EnumThing } from "./dep"; dep.ts: export enum EnumThing { .... } Now if I build both files, insid file.cjs I get: var import_external_dep = ___toESM(require("@...
Alex's user avatar
  • 66.9k
0 votes
0 answers
45 views

How do I expose the DayOfWeek enum in my interface?

In my COM DLL I want to include a DayOfWeek property: private DayOfWeek _MeetingDay; When I will my wrapper in C++ and examine the interface: virtual HRESULT __stdcall get_MeetingDay ( /*[out,...
Andrew Truckle's user avatar
-1 votes
0 answers
33 views

Custom descriptive enum class in Python

I have implemented a custom enum class for Python that satisfies following requirements: All enums are hard coded and cannot be added during run time Every enum value has a unique (in that specific ...
lutrarutra's user avatar
0 votes
1 answer
56 views

Escaping special characters in Ballerina

I need to define a MembershipStatus Enum as depicted below. public enum MembershipStatus { INVITED, REGISTERED, DEACTIVATED, RE-INVITED } It says operator '-' not defined for '...
Malintha Ranasinghe's user avatar
-1 votes
0 answers
43 views

How to use a previously defined enum type in an enum class using the common lisp library defenum

I'm in the process of rewriting Java's UserAgentUtils library using common LISP language to improve my ability to use common LISP language. The java UserAgentUtils library uses a number of enumerated ...
catmore's user avatar
0 votes
1 answer
34 views

Swift, enum doesn't work inside a struct. Errors: Type '<enum name>' has no member '<enum member>', Cannot find '<enum name>' in scope

I am learning Swift and encountered a problem while doing a project from Codecademy to practice enumerations. I have an enum inside a struct, but cannot create an instance of it with any member of ...
Kris's user avatar
  • 3
0 votes
0 answers
13 views

Override the usage of calling an enum class in Python [duplicate]

I have what is probably a very obscure problem. My python script is intended to be ran from the command line with some command line arguments. Each argument needs to be parsed into a type more useful ...
Harry's user avatar
  • 193
1 vote
2 answers
52 views

warning for initialized enum variable : type defaults to 'int' in declaration of 'etatCourant' [-Wimplicit-int]

I'm having a warning when I tried to initialize my enum variable. Here is the code : enum etatCourant {REPOS, MARCHE_AV, MARCHE_AR, ERREUR}; etatCourant = REPOS; Here is the warning : type defaults ...
Classy Fied's user avatar
0 votes
0 answers
36 views

Can't seed objects with enum using HasData() and Entity Framework

I have an issue as Entity Framework throws an exception when I want to seed data using HasData(), because object has enum property. The problem started to appear when I switched string Name to enum ...
JakubCzura's user avatar
1 vote
3 answers
68 views

How can I have enum of interval type instead of single integer type?

I want to assign a String/behavior to each interval [0,1), [1,2), ..., [4, 5]. For a general enum class we can assign just an integer to each String: public enum Behavior { SMILE(4), FUNNY(3),...
user21193451's user avatar
0 votes
1 answer
47 views

Vscode does not autocomplete on functional Enum in python

I am trying to create an Enum class using the functional API and wanted to have autocompletion once I call the enum class. However vscode does not seem to work if the Enum is created using a temp ...
Daniel Lemus's user avatar
1 vote
1 answer
68 views

operator<< for enum class just doesn't work

I have the following code: logging.hxx #include <iostream> #include <string> #include <sstream> #include "singleton.hxx" #include "utils.hxx" class FGaugeLogger:...
TheEagle's user avatar
  • 5,818
2 votes
1 answer
121 views

std::is_enum_v<std::byte> evaluates to true [duplicate]

According to the standard reference, std::is_enum_v evaluates to true for enumeration types and to false otherwise. An enumeration type starts with an enum key, i.e. either one of enum, enum class or ...
Mohammed Li's user avatar
-1 votes
0 answers
31 views

Why do I get an AttributeError when importing my enum class?

I'm a little confused with why I'm getting an AttributeError from my enum class I'm importing. Here's the code I've written: My enum class that's being imported into another file from enum import Enum ...
Classified's user avatar
  • 5,759
0 votes
1 answer
37 views

TypeScript: Error when using string enum inside another enum and comparing it with strings

I have string enum and I want to use it inside another enum. But then if I want to compare enum item with a string I get an error. The last line of this code gives error. Why? And how to make it work? ...
Anton Fil's user avatar
  • 223
0 votes
2 answers
31 views

Named values for a Kotlin Enum item

I have a test class that will have difficulty, which values are configured in an AppSettings.kt class "Difficulty" has five possible values as follows: VeryEasy Easy Medium Difficult ...
Diego Perez's user avatar
  • 2,186

1
2 3 4 5
446