Sc8 - Scala Functions For Java 8

Using Scala libraries from Java 8 can be difficult, because Scala's functions are traits, and not recognised as a FunctionalInterface by the Java compiler. Sc8 is a simple conversion library that converts Java lambdas to Scala functions.

License

License

GroupId

GroupId

com.github.eirslett
ArtifactId

ArtifactId

sc8
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Sc8 - Scala Functions For Java 8
Using Scala libraries from Java 8 can be difficult, because Scala's functions are traits, and not recognised as a FunctionalInterface by the Java compiler. Sc8 is a simple conversion library that converts Java lambdas to Scala functions.
Project URL

Project URL

https://github.com/eirslett/sc8
Source Code Management

Source Code Management

https://github.com/eirslett/sc8

Download sc8

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.eirslett/sc8/ -->
<dependency>
    <groupId>com.github.eirslett</groupId>
    <artifactId>sc8</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.eirslett/sc8/
implementation 'com.github.eirslett:sc8:0.1.0'
// https://jarcasting.com/artifacts/com.github.eirslett/sc8/
implementation ("com.github.eirslett:sc8:0.1.0")
'com.github.eirslett:sc8:jar:0.1.0'
<dependency org="com.github.eirslett" name="sc8" rev="0.1.0">
  <artifact name="sc8" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.eirslett', module='sc8', version='0.1.0')
)
libraryDependencies += "com.github.eirslett" % "sc8" % "0.1.0"
[com.github.eirslett/sc8 "0.1.0"]

Dependencies

provided (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.0

test (2)

Group / Artifact Type Version
com.twitter : util-core_2.10 jar 6.4.0
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

THIS PROJECT IS OUTDATED

3 years after making this project, Scala 2.12 has finally been released, with built-in full interop between Java 8 and Scala! 😄

Sc8 - Scala functions in Java 8

Using Scala libraries from Java 8 can be difficult, because Scala's functions are traits, and not recognised as a FunctionalInterface by the Java compiler. Sc8 is a simple conversion library that converts Java lambdas to Scala functions.

Install via Maven

<dependency>
  <groupId>com.github.eirslett</groupId>
  <artifactId>sc8</artifactId>
  <version>0.1.0</version>
</dependency>

Using the library

In your Java file, import F (and/or C if required):

import static com.github.eirslett.sc8.Sc8.C;
import static com.github.eirslett.sc8.Sc8.F;

What you have to do, is to wrap your lambda with F(...), for example:

result = someList.map(F(s -> s.toUpperCase()));

The F function converts the lambda into a Scala function for you. If your lambda returns void, use C instead:

myFuture.onSuccess(C(s -> System.out.println(s)));

Examples

Look at the tests for more examples.

Building

You need Java 8 and Maven to build this project. (Get Java 8 here: https://jdk8.java.net/download.html)

$ mvn clean package

If you don't want to install jdk8 globally, you can put it in a folder "jdk1.8.0" inside this project, and build with the "localjdk" profile:

$ mvn clean package -Plocaljdk

Generating sources

The Java and Scala sources are for the most part auto-generated, by the PHP-script "genfuncs.php". To generate sources, you will need PHP. Run $ php genfuncs.php to generate.

Versions

Version
0.1.0