Export to GitHub

functionaljava - issue #9

Add Integers.parse()


Posted on Jun 13, 2009 by Swift Elephant

public static final Option<Integer> parse(String) { try { return Option.<Integer>some(Integer.parseInt(String)); } catch(NumberFormatException ex) { return Option.<Integer>none(); } }

public static final F<String, Option<Integer>> parse = new F<String, Option>() { public Option<Integer> f(String text) { return parse(text); } }

Comment #1

Posted on Jun 13, 2009 by Swift Elephant

Similar would be useful on the other number types.

Comment #2

Posted on Jun 13, 2009 by Swift Lion

How about ?

parseInt :: String -> Validation NumberFormatException Integer

readInt :: String -> Option Integer

Comment #3

Posted on Jun 13, 2009 by Swift Elephant

Sure, sounds good to me. I've never used the Validation parts of FJ, but it sounds smart to use the name "parseInt" when you can get the Exception back like you would in "normal" Java.

Comment #4

Posted on Jun 14, 2009 by Quick Rabbit

Integers.fromString already exists as a first-class function.

There's also Validation.parseInt already.

Comment #5

Posted on Jun 14, 2009 by Swift Elephant

Oh, I didn't see that in svn. Great!

Comment #6

Posted on Aug 19, 2009 by Quick Rabbit

Not implementing, since there are alternatives.

Status: WontFix

Labels:
Type-Defect Priority-Medium