FunkyJFunctional
FunkyJFunctional copied to clipboard
A funky way to use functional programming in Java
Are you Funky?
There is no such thing as functional programming in Java, but sometimes we emulate it using anonymous classes.
FunkyJFunctional (aka FJF) provides a new way to do functional programming in Java, using some Java syntactic sugar: method local class declarations and init blocks.
FJF integrates with many different frameworks. If not already available, feel free to implement a new funky module for the framework you love!
A few examples with different frameworks:
- Classic Java, with a funky Runnable
public void sayHelloInExecutor(ExecutorService executor) {
class Hello {{ System.out.println("Hello Funky World"); }}
executor.execute(withRun(Hello.class));
}
public Iterable<User> filterMinors(Iterable<User> users) {
class Minor extends Pred<User> {{ out = in.getAge() < 18; }}
return filter(users, withPred(Minor.class));
}
- Functional Java, with a funky F
public static List<Integer> factors(final int number) {
class Factor extends FF<Integer, Boolean> {{ out = number % in == 0; }}
return range(1, number + 1).filter(withF(Factor.class, number));
}
- FEST-Assert, with a funky Condition
@Test
public void getMajorUsers_returns_no_minor_User() {
List<User> majorUsers = userService.getMajorUsers();
class Minor extends Cond<User> {{ out = in.getAge() < 18; }}
assertThat(majorUsers).noneIs(Minor.class);
}
- Wicket, with a funky AbstractReadOnlyModel
class FortyTwo extends AROM<String> {{ out = "42"; }}
AbstractReadOnlyModel<String> readOnlyModel = withAROM(FortyTwo.class);
- Swing, with a funky ActionListener
class BtonClick extends ActL {{ doSomething(e); }}
jButton.addActionListener(withActL(BtonClick.class));
Sounds funky? We think it is ;-).
Informations
- It's pure Java, no magic involved. See How it works for details.
- All modules have 100% code coverage.
- To use FJF, Download the Maven artifacts.
- See the Detailed example to get into details.
- The latest release is the 1.0 version, see the release notes for more information.
- Licensed under the Apache License, v2.0.
Help
Looking for the documentation? Have a look at the Funky javadoc!
Any question? Please ask them on the dedicated Google Group.
Continuous Integration
FJF has continuous integration thanks to CloudBees DEV@Cloud free plan for FOSS projects.