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

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.

主站蜘蛛池模板: 子洲县| 山东| 集贤县| 金湖县| 高陵县| 东阿县| 易门县| 延津县| 宣化县| 新乡市| 鄄城县| 修武县| 清水县| 夏津县| 泗阳县| 旬邑县| 山阴县| 桓仁| 商水县| 奈曼旗| 湖南省| 洪江市| 张北县| 静乐县| 盱眙县| 东乌| 睢宁县| 蒲江县| 锡林郭勒盟| 武功县| 岫岩| 潍坊市| 石景山区| 福州市| 阜城县| 武义县| 葫芦岛市| 宁城县| 凤台县| 呼玛县| 抚顺县|