Skip to content

Commit 8c88a73

Browse files
author
Mark Perry
committed
Added conversion from fj to the base Java 8 function types
1 parent 710c80f commit 8c88a73

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ build
1010
.settings
1111
.classpath
1212
.project
13-
14-
13+
.DS_Store
1514

java8/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
buildscript {
3+
repositories {
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath 'me.tatarka:gradle-retrolambda:1.3.1'
9+
}
10+
}
11+
12+
apply plugin: 'java'
13+
apply plugin: 'retrolambda'
14+
15+
defaultTasks 'build'
16+
17+
repositories {
18+
mavenCentral()
19+
}
20+
21+
retrolambda {
22+
jdk System.getenv("JAVA8_HOME")
23+
oldJdk System.getenv("JAVA7_HOME")
24+
javaVersion JavaVersion.VERSION_1_7
25+
}
26+
27+
dependencies {
28+
// compile 'org.slf4j:slf4j-api:1.7.5'
29+
compile project(":core")
30+
31+
testCompile "junit:junit:4.11"
32+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package fj.data;
2+
3+
import fj.F;
4+
import fj.F2;
5+
import fj.P1;
6+
7+
import java.util.function.BiFunction;
8+
import java.util.function.Function;
9+
import java.util.function.Supplier;
10+
11+
/**
12+
* Created by mperry on 3/06/2014.
13+
*/
14+
public final class Java8 {
15+
16+
private Java8() {
17+
throw new UnsupportedOperationException();
18+
}
19+
20+
public static <A> P1<A> toP1(Supplier<A> f) {
21+
return () -> f.get();
22+
}
23+
24+
public static <A> Supplier<A> toSupplier(P1<A> p) {
25+
return () -> p._1();
26+
}
27+
28+
public static <A, B> F<A, B> toF(Function<A, B> f) {
29+
return a -> f.apply(a);
30+
}
31+
32+
public static <A, B> F<A, B> toFunction(F<A, B> f) {
33+
return a -> f.f(a);
34+
}
35+
36+
public static <A, B, C> F2<A, B, C> toF2(BiFunction<A, B, C> f) {
37+
return (a, b) -> f.apply(a, b);
38+
}
39+
40+
public static <A, B, C> BiFunction<A, B, C> toBiFunction(F2<A, B, C> f) {
41+
return (a, b) -> f.f(a, b);
42+
}
43+
44+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
include 'core', 'demo', "tests", "consume"
2+
include 'core', 'demo', "tests", "consume", "java8"
33
// The final Java 8 release, (build 1.8.0-b132) does not work with Gradle and the Scala plugin
44
// see http://issues.gradle.org/browse/GRADLE-3023
55

0 commit comments

Comments
 (0)