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

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.

主站蜘蛛池模板: 巴南区| 莆田市| 荣成市| 岑巩县| 璧山县| 平果县| 嵊泗县| 宜良县| 绥芬河市| 康平县| 镇坪县| 万年县| 郸城县| 房山区| 抚顺市| 葫芦岛市| 合作市| 徐汇区| 乌海市| 保亭| 靖江市| 泸溪县| 三穗县| 白河县| 威宁| 张家口市| 茌平县| 吴堡县| 成都市| 徐闻县| 义马市| 潜江市| 湖南省| 句容市| 顺义区| 鹤壁市| 阿拉尔市| 吐鲁番市| 沙雅县| 青神县| 安乡县|