Monday 11 March 2013

Multithreaded Higher Order Function Library for Java

jHighFun

If someone asked to switch back to Java after the experience in functional programming language such as Scala, the obvious answer would be "why? I am feeling quite ok here!"

I agree too. Functional programming languages are on boom because of the flexibility and many more  in built feature which if you want to achieve in Java will eventually lead to lots of boiler plate code and it  looks messier !

Out of the many features available, I found Higher Order Functions  amiable as they facilitate modular way of coding when it comes to define a logic on any sort of collections. Every time i code in Java, i miss them so much, so i made my mind to create a simple  and small library for Higher Order Function which will also have in built concurrent execution capabilities.

Use of Higher Order Functions have following advantages

•  Parameterizable parallelism
•  Improved program modularity
•  Scalable programming
•  Recursion
•  Zero run-time cost in most cases
•  Expressiveness of a visual syntax

So lets get started.

You can download library from here.

This library lets you use following functions.

Just do static import org.highfun.util.FunctionUtil into your java file start using them, be careful while using the overloaded methods which accepts "noOfThreads" as last argument and tries to execute function concurrently.

If you want to use your own custom thread pool, then mention it as value of Java system property "org.highfun.threadpool". The value of this property would be JNDI look up reference for Thread Pool(which implements ExecutorService) which can be managed outside this library. If not mentioned a default unbounded thread pool will be used.

The Github repo:-

https://github.com/corporatepiyush/jHighFun


No comments:

Post a Comment