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 implicit helpers for numeric arguments #1138

Merged
merged 3 commits into from
Dec 19, 2014
Merged

Add implicit helpers for numeric arguments #1138

merged 3 commits into from
Dec 19, 2014

Conversation

wbertelsen
Copy link
Contributor

Similar to RangedArgs this captures logic for handling numeric arguments. I could also imagine this logic living on Args itself.


class TypedArgs(val args: Args) extends AnyVal {

private def asType[T](f: (String, String) => T): (String, String) => T = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'm not sure you are getting any mileage out of this. Couldn't you just inline the parsing in the methods below? You don't expose a generic way to use this.
  2. NumberFormatException is too specific here. I would have gone with:
import scala.util.NonFatal
try f(key, value) catch {
  case NonFatal(_) => throw ArgsException(s"Invalid value ${value} for -- ${key}")
}

@johnynek
Copy link
Collaborator

This needs tests.

@wbertelsen
Copy link
Contributor Author

I'll give this another pass and some tests and update.

@johnynek
Copy link
Collaborator

RangedArgs was old code that was originally internal to Twitter. We could
revist that as well.

On Thu, Dec 18, 2014 at 10:34 AM, Will Bertelsen notifications@github.com
wrote:

I'll give this another pass and some tests and update.


Reply to this email directly or view it on GitHub
#1138 (comment).

Oscar Boykin :: @posco :: http://twitter.com/posco

@johnynek
Copy link
Collaborator

Thanks for the contribution!

johnynek added a commit that referenced this pull request Dec 19, 2014
Add implicit helpers for numeric arguments
@johnynek johnynek merged commit 805ed39 into twitter:develop Dec 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants