Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Our company has been slowly converting a medium-sized (~100K LOC) Java codebase to take advantage of some Java 8 features. One example is a utility method that accepts a String DB query and then executes a Consumer<ResultSet> for each resulting row. The utility method creates the connection, uses try-with-resources to ensure that it's properly closed, etc. This makes a lot of code a lot cleaner.

But unfortunately, many ResultSet operations can throw SQLException. So we created a `ConsumerE<T, E extends Exception>` to use in such cases, so that we can allow some lambdas to throw exceptions where it is sensible (InterruptedException, SQLException, and IOException being the major culprits).

Pretty soon we ended up with FunctionE, BiFunctionE, and so on.

At the same time, we found a need for more interfaces, such as ObjIntFunction<T, R>, that are not provided by JDK 8.

Rather than continuing to implement these on an as-needed basis, I decided to just solve the problem once-and-for-all by creating this library.



I had to register for this. You have pretty much tried to invent Either via code generation. I suggest you look at functionaljava's Either for further reference.

Code generation is in my experience a clear indication that the problem you have has not really been understood.


I understand Either, and I would absolutely prefer to be using it. That was going to be one of my follow up projects, and it would depend on this one.

I took a look functionaljava, and it doesn't provide the following:

    Either<IOExeption, String> line = Either.from(reader::getLine);
For that, you would need to have a signature like:

    static <E extends Exception, R> Either<E, R> from(NilToObjE<R, E> f);
That's exactly what this library gives you.


Have you considered RxJava?


For?


Do you know about Scala?


Yes.


It sort of seems like you've spent a lot of effort to re-invent a less good version of scala? Why not Scala?


This was perhaps a 20-hour project, and we're already using it in our Java codebase. Are you instead recommending a Scala rewrite for a 100,000-line production system?


> Are you instead recommending a Scala rewrite for a 100,000-line production system?

Why? Even if a rewrite/translation of such a small system was perfectly possible, it's not necessary because of the excellent Scala -> Java interop.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: