zoukankan      html  css  js  c++  java
  • Scala 柯里化

    在计算机科学中,柯里化(Currying)是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术

    def clh (a : Int )( b : Int ) = a + b       //> clh: (a: Int)(b: Int)Int
          
          var oo = clh(8)(8)                          //> oo  : Int = 16
          
          var pp = clh(2)_                            //> pp  : Int => Int = <function1>
          pp(2)                                       //> res3: Int = 4
          
         def ppppp(a : Int )(b : Int )(c : Int )(d : Int ) = a+b*c-d
                                                      //> ppppp: (a: Int)(b: Int)(c: Int)(d: Int)Int
          
          
          ppppp(2)(3)(3)(4)                           //> res4: Int = 7
          
          val l = ppppp(2)_                           //> l  : Int => (Int => (Int => Int)) = <function1>
          
          val pl = l(3)(3)(4)                         //> pl  : Int = 7

       

  • 相关阅读:
    申论1
    why factory pattern and when to use factory pattern
    jvm的字符串池
    is assembler instruction and machine instuction atomic
    jvm本身的多线程机制
    final
    java类的加载
    path和classpath的用途
    jar -cmf file1 file2 file3命令
    MANIFEST.MF中的MF是什么意思
  • 原文地址:https://www.cnblogs.com/qunjian/p/6144248.html
Copyright © 2011-2022 走看看