Skip to content

Instantly share code, notes, and snippets.

@paulp
Created September 20, 2015 12:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/846dbd5a67c6bed3c2e9 to your computer and use it in GitHub Desktop.
Save paulp/846dbd5a67c6bed3c2e9 to your computer and use it in GitHub Desktop.
Implicit classes translating scala lambdas into java.util.function classes.
package psp
package jtos
import java.{ util => ju }, ju.{ stream => jus, function => juf }, jus._
import scala.annotation.unchecked.{ uncheckedVariance => uV }
object generated {
implicit final class BiConsumer[-T1, -T2](f: (T1, T2) => Unit) extends juf.BiConsumer[T1 @uV, T2 @uV] { def accept(x1: T1, x2: T2): Unit = f(x1, x2) }
implicit final class BiFunction[-T1, -T2, +R](f: (T1, T2) => R) extends juf.BiFunction[T1 @uV, T2 @uV, R @uV] { def apply(x1: T1, x2: T2): R = f(x1, x2) }
implicit final class BinaryOperator[T](f: (T, T) => T) extends juf.BinaryOperator[T] { def apply(x1: T, x2: T): T = f(x1, x2) }
implicit final class BooleanSupplier(f: () => Boolean) extends juf.BooleanSupplier { def getAsBoolean(): Boolean = f() }
implicit final class Consumer[-T](f: T => Unit) extends juf.Consumer[T @uV] { def accept(x: T): Unit = f(x) }
implicit final class DoubleBinaryOperator(f: (Double, Double) => Double) extends juf.DoubleBinaryOperator { def applyAsDouble(x1: Double, x2: Double): Double = f(x1, x2) }
implicit final class DoubleConsumer(f: Double => Unit) extends juf.DoubleConsumer { def accept(x: Double): Unit = f(x) }
implicit final class DoubleFunction[+R](f: Double => R) extends juf.DoubleFunction[R @uV] { def apply(x: Double): R = f(x) }
implicit final class DoublePredicate(f: Double => Boolean) extends juf.DoublePredicate { def test(x: Double): Boolean = f(x) }
implicit final class DoubleSupplier(f: () => Double) extends juf.DoubleSupplier { def getAsDouble(): Double = f() }
implicit final class DoubleToIntFunction(f: Double => Int) extends juf.DoubleToIntFunction { def applyAsInt(x: Double): Int = f(x) }
implicit final class DoubleToLongFunction(f: Double => Long) extends juf.DoubleToLongFunction { def applyAsLong(x: Double): Long = f(x) }
implicit final class DoubleUnaryOperator(f: Double => Double) extends juf.DoubleUnaryOperator { def applyAsDouble(x: Double): Double = f(x) }
implicit final class IntBinaryOperator(f: (Int, Int) => Int) extends juf.IntBinaryOperator { def applyAsInt(x1: Int, x2: Int): Int = f(x1, x2) }
implicit final class IntConsumer(f: Int => Unit) extends juf.IntConsumer { def accept(x: Int): Unit = f(x) }
implicit final class IntFunction[+R](f: Int => R) extends juf.IntFunction[R @uV] { def apply(x: Int): R = f(x) }
implicit final class IntPredicate(f: Int => Boolean) extends juf.IntPredicate { def test(x: Int): Boolean = f(x) }
implicit final class IntSupplier(f: () => Int) extends juf.IntSupplier { def getAsInt(): Int = f() }
implicit final class IntToDoubleFunction(f: Int => Double) extends juf.IntToDoubleFunction { def applyAsDouble(x: Int): Double = f(x) }
implicit final class IntToLongFunction(f: Int => Long) extends juf.IntToLongFunction { def applyAsLong(x: Int): Long = f(x) }
implicit final class IntUnaryOperator(f: Int => Int) extends juf.IntUnaryOperator { def applyAsInt(x: Int): Int = f(x) }
implicit final class LongBinaryOperator(f: (Long, Long) => Long) extends juf.LongBinaryOperator { def applyAsLong(x1: Long, x2: Long): Long = f(x1, x2) }
implicit final class LongConsumer(f: Long => Unit) extends juf.LongConsumer { def accept(x: Long): Unit = f(x) }
implicit final class LongFunction[+R](f: Long => R) extends juf.LongFunction[R @uV] { def apply(x: Long): R = f(x) }
implicit final class LongPredicate(f: Long => Boolean) extends juf.LongPredicate { def test(x: Long): Boolean = f(x) }
implicit final class LongSupplier(f: () => Long) extends juf.LongSupplier { def getAsLong(): Long = f() }
implicit final class LongToDoubleFunction(f: Long => Double) extends juf.LongToDoubleFunction { def applyAsDouble(x: Long): Double = f(x) }
implicit final class LongToIntFunction(f: Long => Int) extends juf.LongToIntFunction { def applyAsInt(x: Long): Int = f(x) }
implicit final class LongUnaryOperator(f: Long => Long) extends juf.LongUnaryOperator { def applyAsLong(x: Long): Long = f(x) }
implicit final class ObjDoubleConsumer[-T](f: (T, Double) => Unit) extends juf.ObjDoubleConsumer[T @uV] { def accept(x1: T, x2: Double): Unit = f(x1, x2) }
implicit final class ObjIntConsumer[-T](f: (T, Int) => Unit) extends juf.ObjIntConsumer[T @uV] { def accept(x1: T, x2: Int): Unit = f(x1, x2) }
implicit final class ObjLongConsumer[-T](f: (T, Long) => Unit) extends juf.ObjLongConsumer[T @uV] { def accept(x1: T, x2: Long): Unit = f(x1, x2) }
implicit final class Predicate[-T](f: T => Boolean) extends juf.Predicate[T @uV] { def test(x: T): Boolean = f(x) }
implicit final class Supplier[+R](f: () => R) extends juf.Supplier[R @uV] { def get(): R = f() }
implicit final class ToDoubleBiFunction[-T1, -T2](f: (T1, T2) => Double) extends juf.ToDoubleBiFunction[T1 @uV, T2 @uV] { def applyAsDouble(x1: T1, x2: T2): Double = f(x1, x2) }
implicit final class ToDoubleFunction[-T](f: T => Double) extends juf.ToDoubleFunction[T @uV] { def applyAsDouble(x: T): Double = f(x) }
implicit final class ToIntBiFunction[-T1, -T2](f: (T1, T2) => Int) extends juf.ToIntBiFunction[T1 @uV, T2 @uV] { def applyAsInt(x1: T1, x2: T2): Int = f(x1, x2) }
implicit final class ToIntFunction[-T](f: T => Int) extends juf.ToIntFunction[T @uV] { def applyAsInt(x: T): Int = f(x) }
implicit final class ToLongBiFunction[-T1, -T2](f: (T1, T2) => Long) extends juf.ToLongBiFunction[T1 @uV, T2 @uV] { def applyAsLong(x1: T1, x2: T2): Long = f(x1, x2) }
implicit final class ToLongFunction[-T](f: T => Long) extends juf.ToLongFunction[T @uV] { def applyAsLong(x: T): Long = f(x) }
implicit final class UnaryOperator[T](f: T => T) extends juf.UnaryOperator[T @uV] { def apply(x: T): T = f(x) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment