Hi ```enum class Role(val letter: Char) { APPR...
# announcements
a
Hi
Copy code
enum class Role(val letter: Char) {
    APPROVER('U'),
    ADMIN('D'),
    INQUIRER('R'),
    OPERATOR('O');
}
we have create this enum for code readability and we don't have direct control over how server is returning constants for the user roles, so they have done it this way 'U' , R etc apiRespose.role = "U" Role.valueOf(apiResponse.role) will not work ,as it is expecting 'APPROVER' as input . How can i achieve same benefit of Role.valueOf( ) wrt ot the 'letter' attribute in the enum
c
Copy code
enum class Role(val letter: Char) {
  APPROVER('U'),
  ADMIN('D'),
  INQUIRER('R'),
  OPERATOR('O');

  companion object {
    fun from(letter: Char) = values().find { it.letter == letter }
  }
}
and use it like
Role.from(letter)
Is this what you’re after?
h
Please don't crosspost. See my answer in #C0B8MA7FA
c
Agreed. (although this had the Q and A before the other channel)
👍 1
a
@hho sorry, i did that , as last message from the moderator mentioned #C0922A726 is no longer QA. I read the message from the moderator only after posting this. So , i posted to this #C0B8MA7FA channel . Sorry for crossposting.
👌 1
@Chris thank you