scala - Extending Enumeration -
I have implemented a method withNameOption
which gives none
If counting member with specific name is not found but I have trouble removing this in one attribute to use it for all enumeration in the app. Currently the code looks like this:
Expand the computation with the type of object file type EnumUtils {type} with the file type = name def name (name: string): option [FileType] = {something (WithName (name))} {case_: NoSuchElementException = & gt; No one} Val Scala, Java, Ruby = Value}
Use this type. Type
wherever possible, type not checked.
I think this is the pattern you are looking for:
Properties EnumUtils {thisenum: enumeration = & gt; Def withNameOption (name: string): option [thisenum.type # Value] = {hold something (thisenum.withName (name)) {case_: NoSuchElementException = & gt; None {}} Object file type EnumUtils {{FileType = Value val value, Java, ruby = Value} With the extension of the math {def main (args: Array [String]): Unit = {println ("Python: "+ FileType.withNameOption (" Python ")) println (" Scala: "+ FileType.withNameOption (" scala "))}
Comments
Post a Comment