如何在scala中创建curried匿名函数?
发布时间:2020-12-16 19:08:12 所属栏目:安全 来源:网络整理
导读:如何在 Scala中创建一个匿名和咖喱功能?以下两个失败: scala (x:Int)(y:Int) = x*yconsole:1: error: not a legal formal parameter (x:Int)(y:Int) = x*y ^scala ((x:Int)(y:Int)) = x*yconsole:1: error: not a legal formal parameter ((x:Int)(y:Int))
如何在
Scala中创建一个匿名和咖喱功能?以下两个失败:
scala> (x:Int)(y:Int) => x*y <console>:1: error: not a legal formal parameter (x:Int)(y:Int) => x*y ^ scala> ((x:Int)(y:Int)) => x*y <console>:1: error: not a legal formal parameter ((x:Int)(y:Int)) => x*y ^ 解决方法
要创建一个curried函数,就好像它是多个函数一样(实际上是这样的情况;-)).
scala> (x: Int) => (y: Int) => x*y res2: Int => Int => Int = <function1> 这意味着你有一个Int从Int到Int的函数. scala> res2(3) res3: Int => Int = <function1> 或者你可以这样写: scala> val f: Int => Int => Int = x => y => x*y f: Int => Int => Int = <function1> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 【数据结构】 第一章 绪论
- Angular 4:http拦截器向其他组件发出事件?
- angularjs-ng-repeat – 无法使用角度ng-repeat渲染Bootstr
- scala – 我的API都是返回Future [Option [T]],如何在comp-
- 使用AngularJS,UI Boostrap和UI路由器时,活动选项卡默认为麻
- angular – 数据表问题 – ERROR TypeError:val.slice不是
- 有没有办法将任意文本传递给Vim?
- 当CL程序被调用为shell脚本时,如何使用quicklisp?
- angular学习资源
- twitter-bootstrap – Bootstrap网格,其间有折叠容器