日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

scala语言示例_标有示例的Scala关键字

發布時間:2025/3/11 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala语言示例_标有示例的Scala关键字 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

scala語言示例

Scala | 任一關鍵字 (Scala | Either Keyword)

Either is a container similar to the option which has two values, they are referred to as children. The left and right children are named as the right child and left child.

是一個類似于選項的容器,該容器具有兩個值,它們被稱為子級。 左邊的孩子和右邊的孩子分別命名為右邊的孩子左邊的孩子

The left child is similar to None class which is used when there can be an error returned.

左子級類似于None類,該類可以在返回錯誤時使用。

The right child is similar to Some class which is used when a vale is to be returned i.e. for the successful execution of code.

正確的子級類似于Some類,該類將在返回谷時即成功執行代碼時使用。

Syntax:

句法:

Either [left, right]

Both left and right are data types of the returned values which can be used to define the results when there are error case or valid case.

左和右均為返回值的數據類型,當出現錯誤情況或有效情況時,可用于定義結果。

理解任一關鍵字工作方式的示例 (Example to understand the working of Either Keyword)

object MyObject {// function defintiondef isEven(number : Int ): Either[String, String] = {if(number%2 == 0){Right(number + " is even.")}elseLeft(number + " is not even.")}// main codedef main(args: Array[String]) {println(isEven(4))println(isEven(95))} }

Output

輸出量

Right(4 is even.) Left(95 is not even.)

翻譯自: https://www.includehelp.com/scala/either-keyword.aspx

scala語言示例

總結

以上是生活随笔為你收集整理的scala语言示例_标有示例的Scala关键字的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。