Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enumeration.valueOf(s:String) method #1505

Closed
scabug opened this issue Nov 12, 2008 · 3 comments
Closed

Add Enumeration.valueOf(s:String) method #1505

scabug opened this issue Nov 12, 2008 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 12, 2008

I propose adding the following method to scala.Enumeration:

  /* Returns a Value from this Enumeration whose name matches the argument <var>s</var>.
   * You must pass a String* set of names to the constructor,
   * or initialize each Enumeration with Value(String),
   * for valueOf to work.
   * @param s an enumeration name
   * @return <tt>Some(Value)</tt> if an enumeration's name matches <var>s</var>, 
   * else <tt>None</tt>
   */
  def valueOf(s:String) = {
    var v: Option[Value] = None
    for( e <- elements ) if (s == e.toString()) v = Some(e)
    v
  }

Attached is a subclass of Enumeration which defines such a
method, and sample Enumerations which use the method to
show how it works for finding/matching values.

@scabug
Copy link
Author

scabug commented Nov 12, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1505?orig=1
Reporter: @DavidBiesack
See #5211
Attachments:

@scabug
Copy link
Author

scabug commented Nov 12, 2008

@DavidBiesack said:
subclass of Enumeration which defines a valueOf method, and some samples

@scabug
Copy link
Author

scabug commented Nov 18, 2008

Geoffrey Alan Washburn (washburn) said:
Applied in r16575.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant