Scala高阶函数 2(以函数作为返回值,函数柯里化,应用函数)

package com.wyh.day01

object ScalaFun4 {
  def main(args: Array[String]): Unit = {

    /**
      * 以函数作为返回值
      */

    def A(s: String): String => String = {
      def B(s1: String): String = {
        s + "\t" + s1

      }

      B
    }

    println(A("Java")("BigData"))


    println("=" * 100)

    /**
      * 函数柯里化
      */

    def A1(s: String)(s1: String): String = {
      s + "函数柯里化" + s1

    }

    println(A1("java")("spark"))


    println("=" * 100)

    /**
      * 应用函数
      */

    def C(s1: String, s2: String): String = {
      s1 + "应用函数" + s2
    }

    println(C("Java", "spark"))
    println(C("Java", "hadoop"))
    println(C("Java", "Hbase"))

    println("=" * 100)

    val function = C("Java", _: String)

    println(function("Hive"))
    println(function("HDFS"))
    println(function("mapreduce"))




  }
}
posted @ 2020-01-20 12:57  Xiaohu_BigData  阅读(557)  评论(0编辑  收藏  举报