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

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.

主站蜘蛛池模板: 公主岭市| 龙井市| 比如县| 辛集市| 新营市| 泰安市| 探索| 阳新县| 陵水| 柘荣县| 志丹县| 开化县| 新津县| 林西县| 宜丰县| 苍梧县| 岗巴县| 五家渠市| 巴林右旗| 乌拉特后旗| 名山县| 浠水县| 龙山县| 敦煌市| 东乌| 石嘴山市| 申扎县| 崇左市| 工布江达县| 迁西县| 巴马| 古蔺县| 兴国县| 福建省| 辛集市| 新密市| 四会市| 临西县| 龙南县| 易门县| 龙井市|