Memoize a Clojure function that takes a lazy sequence as input
<p>How can I have memoize work when the argument to a memoised function is a sequence</p>

<pre><code>(defn foo
    ([x] (println "Hello First") (reduce + x))
    ([x y] (println "Hello Second") (reduce + (range x y))))


(def baz (memoize foo))
</code></pre>

<p>Passing one arg: </p>

<p>1)</p>

<pre><code>(time (baz (range 1 1000000))) ;=&gt; Hello First "Elapsed time: 14.870628 msecs"
</code></pre>

<p>2) </p>

<pre><code>(time (baz (range 1 1000000))) ;=&gt; "Elapsed time: 65.386561 msecs"
</code></pre>

<p>Passing 2 args:</p>

<p>1)</p>

<pre><code>(time (baz 1 1000000)) ;=&gt; Hello Second "Elapsed time: 18.619768 msecs"
</code></pre>

<p>2)</p>

<pre><code>(time (baz 1 1000000)) ;=&gt; "Elapsed time: 0.069684 msecs"
</code></pre>

<p>The second run of the function when passed 2 arguments seems to be what I expect.</p>

<p>However using a vector appears to work...</p>

<pre><code>(time (baz [1 2 3 5 3 5 7 4 6 7 4 45 6 7])) ;=&gt; Hello First "Elapsed time: 0.294963 msecs"


(time (baz [1 2 3 5 3 5 7 4 6 7 4 45 6 7])) ;=&gt; "Elapsed time: 0.068229 msecs"
</code></pre>