Skip to content

tommyettinger/funderby

Repository files navigation

funderby

Java 8+ functional interfaces for primitive types, partly based on Eclipse-Collections.

What is it?

Funderby provides nearly 400 functional interfaces, mostly specialized for primitive types that aren't supported by the standard java.util.function interfaces. There are:

  • Suppliers that return primitive types,
  • Single-argument and dual-argument Predicates,
  • Single-argument and dual-argument Consumers and BiConsumers,
  • Single-argument Functions that return possibly a different type,
  • Dual-argument BiFunctions that either
    • Take two arguments with one type and return possibly a different type, or that
    • Take two arguments of different types and return the second type.

Most of these use a consistent naming format.

  • $TYPE0 Predicate takes a $TYPE0 and returns a boolean.
    • If a functional interface returns boolean here, it is always a Predicate.
  • $TYPE0 $TYPE1 Predicate takes a $TYPE0 and a $TYPE1 and returns a boolean.
  • $TYPE0 Supplier returns a $TYPE0.
  • $TYPE0 Consumer takes a $TYPE0.
  • $TYPE0 $TYPE1 BiConsumer takes a $TYPE0 and a $TYPE1.
  • $TYPE0 To $TYPE1 Function takes a $TYPE0 and returns a $TYPE1.
  • $TYPE0 $TYPE1 To $TYPE2 BiFunction takes a $TYPE0 and a $TYPE1 and returns a $TYPE2.

Types can be Boolean, Byte, Char, Double, Float, Int, Long, Short, or Obj (meaning Object, and always a generic type). Two exceptions are ObjToSameFunction and ObjSameBiConsumer, which only take one generic type parameter because what would be different generic type parameters are the same there. Some functional interfaces are not really necessary because the JDK already provides one with the same name and signature; this library provides duplicates so that platforms like RoboVM can still have functional interface types. On RoboVM, you can use lambdas and have them assignable to interfaces like ObjToObjFunction, which is roughly equivalent to java.util.function.Function.

Why?

I found myself redefining primitive-based functional interfaces fairly often, so I decided to bite the bullet and make as many functional interfaces as I could. Eclipse-Collections does a lot of this work, but it also changes some names in what to me is a counterintuitive way. It also uses java.io.Serializable without a clear reason to do so, and I feel like Serializable is a ticking time bomb in actual use.

How to Get It?

Via Gradle,

api "com.github.tommyettinger:funderby:0.1.1"

If you use GWT, you also need

api "com.github.tommyettinger:funderby:0.1.1:sources"

And in your main .gwt.xml file,

<inherits name="com.github.tommyettinger.funderby" />

If you use Maven, the dependency is:

<dependency>
  <groupId>com.github.tommyettinger</groupId>
  <artifactId>funderby</artifactId>
  <version>0.1.1</version>
</dependency>

With this required if you use GWT, plus the above .gwt.xml line:

<dependency>
  <groupId>com.github.tommyettinger</groupId>
  <artifactId>funderby</artifactId>
  <version>0.1.1</version>
  <classifier>sources</classifier>
</dependency>

License

Licensed under the same license as Eclipse-Collections, the EPL v 1.0 and the EDL v 1.0 .

Trivia

The name comes from the MLB Home Run Derby, which was happening when I was starting to make this library. It also includes "fun" for functional interface.

No, it is not "fun" for "I had a fun time making this." The only fun part was how easy JavaPoet was to work with; JavaPoet was used to generate the many functional interfaces from template-like code.

About

Java 8+ functional interfaces for primitive types

Resources

License

EPL-1.0, Unknown licenses found

Licenses found

EPL-1.0
LICENSE
Unknown
LICENSE-EDL

Stars

Watchers

Forks

Packages

No packages published

Languages