Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're making your own life hard. </p> <pre><code>List&lt;List&lt;Integer&gt;&gt; listOfListOfIntegersBefore = new FunctionArrayList&lt;&gt;(); [...] ((FunctionArrayList&lt;Integer&gt;) listOfIntegersBefore).apply </code></pre> <p>Why not store it as a <code>FunctionArrayList</code> in the first place? Of course you have to cast it this way.</p> <p>Anyway, I find wrapping each list in a functional list a bit annoying, and I'd rather do it with simple static methods: </p> <pre><code>public interface F&lt;S, T&gt; { T apply(S s); } public final class FunctionalStuff { private FunctionalStuff() {} public &lt;S, T&gt; static List&lt;T&gt; map(Collection&lt;? extends S&gt; collection, F&lt;? super S, ? extends T&gt; func) { final List&lt;T&gt; result = new ArrayList&lt;T&gt;(collection.size()); for (S source : collection) result.add(func.apply(source)); return result; } public &lt;S, T&gt; static List&lt;S&gt; filter(Collection&lt;? extends S&gt; collection, F&lt;? super S, Boolean&gt; predicate) { final List&lt;T&gt; result = new ArrayList&lt;T&gt;(collection.size()); for (S source : collection) if (predicate.apply(source)) result.add(source); return result; } // etc etc. } </code></pre> <p>Anyways, please note: I don't advise you to do functional style coding in Java. Wait for closures which will be added in Java 8.</p> <p>Alternatively use a language that embraces functional style: Scala, Javascript, Clojure, Lisp, Mathematica, etc etc, there's a ton of them! Even c(++) seems less annoying at this than Java.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload