由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - java 8 也可以fp啊
相关主题
比较简单的Java数据输入验证问题Scala的思路
iq 140的人说小时候无法理解变量,需要妈妈帮忙scala的def或val是冗余的
java小问题编程的宗派
js: 怎么来监听某个function被call的次数?王垠: 编程的宗派
请教Office Automation Add-in的高手[求教,R, currying]函数编程20行代码,如何debug?
问个算法题请教一个class design的问题
有没有人对curring有研究问一道面试题
fp就是Declarative Programming一个哈希表问题
相关话题的讨论汇总
话题: integer话题: function话题: currying话题: add话题: times
进入Programming版参与讨论
1 (共1页)
l**********n
发帖数: 8443
1
package java8tests ;
import java.util.function.BiFunction ;
import java.util.function.Function ;
public class Currying {
public void currying() {
// Create a function that adds 2 integers
BiFunction adder = ( a, b ) -> a + b ;
// And a function that takes an integer and returns a function
Function> currier = a -> b ->
adder.apply( a, b ) ;
// Call apply 4 to currier (to get a function back)
Function curried = currier.apply( 4 ) ;

// Results
System.out.printf( "Curry : %dn", curried.apply( 3 ) ) ; // ( 4 + 3 )
}
public void composition() {
// A function that adds 3
Function add3 = (a) -> a + 3 ;

// And a function that multiplies by 2
Function times2 = (a) -> a * 2 ;

// Compose add with times
Function composedA = add3.compose( times2 ) ;

// And compose times with add
Function composedB = times2.compose( add3 ) ;

// Results
System.out.printf( "Times then add: %dn", composedA.apply( 6 ) ) ;
// ( 6 * 2 ) + 3
System.out.printf( "Add then times: %dn", composedB.apply( 6 ) ) ;
// ( 6 + 3 ) * 2
}

public static void main( String[] args ) {
new Currying().currying() ;
new Currying().composition() ;
}
}
p*****2
发帖数: 21240
2
还不够噁心的
N*****m
发帖数: 42603
3
这个比scala还差

【在 p*****2 的大作中提到】
: 还不够噁心的
l**********n
发帖数: 8443
4
scala的type很复杂。

【在 N*****m 的大作中提到】
: 这个比scala还差
b*******s
发帖数: 5216
5
java is too difficult to hug new things
b***e
发帖数: 17
6
JVM was designed a long time ago and some of the design choices were made in
restricted ways such that some certain modern features are difficult to
extend. It's a dilemma given that Java needs to maintain its backward
compatibility. To this point, Java's doing much better than Ruby or Python,
which are not always backward compatible.

【在 b*******s 的大作中提到】
: java is too difficult to hug new things
b*******s
发帖数: 5216
7
Java主要是做企业应用的,不后向兼容是不可接受的

in
Python,

【在 b***e 的大作中提到】
: JVM was designed a long time ago and some of the design choices were made in
: restricted ways such that some certain modern features are difficult to
: extend. It's a dilemma given that Java needs to maintain its backward
: compatibility. To this point, Java's doing much better than Ruby or Python,
: which are not always backward compatible.

1 (共1页)
进入Programming版参与讨论
相关主题
一个哈希表问题请教Office Automation Add-in的高手
Check if the sum of two integers in an integer array eqauls to the given number 问个算法题
面试题 -算法?有没有人对curring有研究
两道M软件大公司的最新面世算法题 (转载)fp就是Declarative Programming
比较简单的Java数据输入验证问题Scala的思路
iq 140的人说小时候无法理解变量,需要妈妈帮忙scala的def或val是冗余的
java小问题编程的宗派
js: 怎么来监听某个function被call的次数?王垠: 编程的宗派
相关话题的讨论汇总
话题: integer话题: function话题: currying话题: add话题: times