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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

scala 函数中嵌套函数_Scala合成函数

發布時間:2023/12/1 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala 函数中嵌套函数_Scala合成函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

scala 函數中嵌套函數

Scala中的合成功能 (Composition function in Scala)

Scala composition function is a way in which functions are composed in program i.e. mixing of more than one functions to extract some results. In Scala programming language, there are multiple ways to define the composition of a function. They are,

Scala組合函數是一種在程序中組合函數的方法,即混合多個函數以提取一些結果。 在Scala編程語言中,有多種方法來定義函數的組成。 他們是,

  • Using compose Keyword

    使用撰寫關鍵字

  • Using andthen Keyword

    使用然后關鍵詞

  • Passing method to method

    傳遞方法

  • 1)使用Compose關鍵字的Scala合成功能 (1) Scala composition function using Compose Keyword )

    The compose keyword in Scala is valid for methods that are defined using "val" keyword.

    Scala中的compose關鍵字對使用“ val”關鍵字定義的方法有效。

    Syntax:

    句法:

    (method1 compose method2)(parameter)

    Program:

    程序:

    object MyObject { def main(args: Array[String]) { println("The percentage is "+(div compose mul)(435)) } val mul=(a: Int)=> { a * 100} val div=(a: Int) =>{ a / 500} }

    Output

    輸出量

    The percentage is 87

    2)使用andThe關鍵字的Scala合成函數 (2) Scala composition function using andThen Keyword)

    Another composition keyword that works on function defined using val keyword function is andThen.

    對使用val關鍵字function定義的函數起作用的另一個組合關鍵字是andThen 。

    Syntax:

    句法:

    (method1 andThen method2)(parameter)

    Program:

    程序:

    object myObject { def main(args: Array[String]) { println("The percentage is "+(mul andThen div)(435)) } val mul=(a: Int)=> { a * 100} val div=(a: Int) =>{ a / 500} }

    Output

    輸出量

    The percentage is 87

    3)Scala合成函數的使用方法 (3) Scala composition function using method to method)

    One more way to declaring composition function in Scala is passing a method as a parameter to another method.

    在Scala中聲明復合函數的另一種方法是將一種方法作為參數傳遞給另一種方法。

    Syntax:

    句法:

    function1(function2(parameter))

    Program:

    程序:

    object myObject { def main(args: Array[String]) { println("The percentage is "+ ( div(mul(456)) ))} val mul=(a: Int)=> { a * 100} val div=(a: Int) =>{ a / 500} }

    Output

    輸出量

    The percentage is 91

    翻譯自: https://www.includehelp.com/scala/scala-composition-function.aspx

    scala 函數中嵌套函數

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的scala 函数中嵌套函数_Scala合成函数的全部內容,希望文章能夠幫你解決所遇到的問題。

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