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 ElephantSimilar would be useful on the other number types.
Comment #2
Posted on Jun 13, 2009 by Swift LionHow about ?
parseInt :: String -> Validation NumberFormatException Integer
readInt :: String -> Option Integer
Comment #3
Posted on Jun 13, 2009 by Swift ElephantSure, 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 RabbitIntegers.fromString already exists as a first-class function.
There's also Validation.parseInt already.
Comment #5
Posted on Jun 14, 2009 by Swift ElephantOh, I didn't see that in svn. Great!
Comment #6
Posted on Aug 19, 2009 by Quick RabbitNot implementing, since there are alternatives.
Status: WontFix
Labels:
Type-Defect
Priority-Medium