title: Function composition in Java
body: <p>I'm trying to implement a lazy sequence (meaning that the next item is only calculated when you invoke the step function), and one of the methods it should have is &quot;<code>map</code>&quot; which receives a function that affects all the members.<br />
  The most elegant way to do this is to use function composition, and assign the new function to the function variable, but since functions are not first class values in Java I have no idea how to do this.</p>
  <p>I thought about having a class that only contains a function, as a sort of &quot;function pointer&quot; wrapper, but I don't see how that can be used for composition.</p>
  <p>Edit: question is homework related.<br />
  Also, it should be able to handle multiple compositions along the lines of <code>map(map(map(stepFunction())))</code> (&quot;<code>map</code>&quot; in this case being the function given through the method &quot;map&quot;).</p>