In the Wild

We can see one of the more useful applications of lazy sequences in nREPL,[20] a library that enables you to create a client/server rendition of a REPL, where the client sends Clojure expressions off to a server, which evaluates them and sends back the results. Here’s the sequence:

 (repeatedly #(transport/recv transport timeout))

The repeatedly function is the function-driven equivalent of repeat. Instead of returning the same value over and over, repeatedly calls the function you pass in over and over, returning a lazy sequence of the resulting values. The repeatedly function is useful in those situations where you are dealing with side effects—presumably you will get something different back from the repeated calls to the function. ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.