官术网_书友最值得收藏!

Optional parsing for string literals

In Scala 2.13, StringOps has been extended with methods that return Option for string-literals parsing. Supported types include all numeric types and Boolean.

The new methods can greatly simplify the processing of user-provided data without the need to wrap the calls with the exception-handling, as shown in the following example:

scala> "10".toIntOption
res3: Option[Int] = Some(10)
scala> "TrUe".toBooleanOption
res4: Option[Boolean] = Some(true)
scala> val bool = "Not True"
bool: String = Not True
scala> bool.toBooleanOption
res5: Option[Boolean] = None

The optional Boolean parsing ignores the case of the argument the same way the exception-throwing toBoolean method does.

主站蜘蛛池模板: 舒城县| 出国| 宿州市| 密山市| 深水埗区| 连平县| 汉沽区| 北流市| 宾川县| 长治县| 石棉县| 永登县| 公安县| 渝中区| 阿勒泰市| 焦作市| 政和县| 北流市| 当涂县| 罗甸县| 惠东县| 惠州市| 芦溪县| 信阳市| 台山市| 灌云县| 佛山市| 东辽县| 乐至县| 天祝| 纳雍县| 灵武市| 淮安市| 庆云县| 綦江县| 邓州市| 五华县| 广平县| 盘山县| 万宁市| 绿春县|