I just checked in an almost complete reimplementation of clojure.contrib.stream-utils. It is now centered around an interface for data streams that consists of the single multimethod stream-next. It takes a stream state as its argument and returns the next value of the stream as well as the updated state.
As an example of how a stream can be defined using this interface, consider the following definition of a stream of Fibonacci numbers: ; Define a type representing the state of the stream (deftype ::fib-stream last-two-fib) ; Define the stream-next implementation and derive ::fib-stream from :clojure.contrib.stream-utils/stream (defstream ::fib-stream [fs] (let [[n1 n2] fs] [n1 (last-two-fib [n2 (+ n1 n2)])])) ; Define the stream by its initial state (def fib-stream (last-two-fib [0 1])) ; Look at the first 10 values (take 10 (clojure.contrib.seq-utils/seq-on fib-stream)) Almost all of the stream utility functions in the module are implemented in the form of specific stream state types. While less concise than lazy sequences, these stream state definitions have the advantage of making the state explicit. You can keep references to as many stream states as you wish, store them in a database, etc., and reconstruct the stream from them at any later time. Moreover, the stream contents are never cached, so keeping a reference to a state does not lead to memory problems. Konrad. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---