Skip to content

Commit 34ab8c1

Browse files
committed
regenerate site
1 parent 8b0856e commit 34ab8c1

File tree

4 files changed

+107
-80
lines changed

4 files changed

+107
-80
lines changed

articles/language/interop/index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,34 @@ <h2>Language: Java Interop</h2>
324324
(f)))]
325325
(.run obj)) ; ⇒ nil
326326
;; outputs "Executed from a function"
327-
</code></pre><p>TBD: more realistic examples | <a href="https://github.com/clojure-doc/clojure-doc.github.io#how-to-contribute">How to Contribute</a></p><h2 id="clojure-functions-implement-runnable-and-callable">Clojure Functions Implement Runnable and Callable</h2><p>Note that Clojure functions implement <code>java.lang.Runnable</code> and
327+
</code></pre><p>TBD: more realistic examples | <a href="https://github.com/clojure-doc/clojure-doc.github.io#how-to-contribute">How to Contribute</a></p><h2 id="consuming-java-streams">Consuming Java Streams</h2><p>The <a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html">Java Streams API</a>
328+
introduced in Java 8 provided a way to work with collections of data in a
329+
functional style: <code>filter</code>, <code>map</code>, <code>reduce</code>, <code>iterate</code>, and so on. We're used
330+
to this in Clojure because <code>clojure.core</code> provides these operations across
331+
sequences. In Clojure, that means we can apply those functions to anything
332+
that can be coerced into a sequence, such as vectors, lists, sets, maps, and
333+
anything in the Java world that implements
334+
<a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Iterable.html"><code>java.lang.Iterable</code></a>.
335+
Unfortunately, Java Streams are not <code>Iterable</code> so they were hard to consume
336+
with Clojure until Clojure 1.12 added four functions that can consume them:</p><ul><li><code>(stream-seq! stream)</code> -- consume a Stream and produce a Clojure sequence,</li><li><code>(stream-reduce! f init stream)</code> -- reduce a Stream using <code>f</code> and the <code>init</code> value; <code>init</code> is optional,</li><li><code>(stream-transduce! xf f init stream)</code> -- transduce a Stream using <code>xf</code>, <code>f</code> and the <code>init</code> value; <code>init</code> is optional,</li><li><code>(stream-into! to-coll xf stream)</code> -- consume a Stream and add its elements to a collection <code>coll</code>; <code>xf</code> is optional.</li></ul><pre><code class="clojure">user=&gt; (import '(java.util.stream Stream))
337+
java.util.stream.Stream
338+
user=&gt; (Stream/iterate 0 inc) ; like Clojure's (iterate inc 0)
339+
#object[java.util.stream.ReferencePipeline$Head 0x3291cfad "java.util.stream.ReferencePipeline$Head@3291cfad"]
340+
user=&gt; (take 5 *1) ; streams are not coercible to sequences
341+
Error printing return value (IllegalArgumentException) at clojure.lang.RT/seqFrom (RT.java:577).
342+
Don't know how to create ISeq from: java.util.stream.ReferencePipeline$Head
343+
user=&gt; (Stream/iterate 0 inc)
344+
#object[java.util.stream.ReferencePipeline$Head 0x10fa7b74 "java.util.stream.ReferencePipeline$Head@10fa7b74"]
345+
user=&gt; (take 5 (stream-seq! *1)) ; consume the stream as a sequence
346+
(0 1 2 3 4)
347+
</code></pre><p>Several methods in the Java standard library produce Streams, for example:</p><pre><code class="clojure">user=&gt; (import '(java.nio.file Files Path))
348+
java.nio.file.Path
349+
user=&gt; (Files/lines (Path/of "deps.edn" (into-array String []))) ; =&gt; Stream
350+
#object[java.util.stream.ReferencePipeline$Head 0x3fbda43d "java.util.stream.ReferencePipeline$Head@3fbda43d"]
351+
user=&gt; (stream-into! [] (filter #(re-find #"deps" %)) *1)
352+
["{:deps {org.clojure/clojure {:mvn/version \"RELEASE\"}}"
353+
" :build {:deps {io.github.clojure/tools.build"]
354+
</code></pre><h2 id="clojure-functions-implement-runnable-and-callable">Clojure Functions Implement Runnable and Callable</h2><p>Note that Clojure functions implement <code>java.lang.Runnable</code> and
328355
<code>java.util.concurrent.Callable</code> directly so you can pass functions to
329356
methods found in various classes from the <code>java.util.concurrent</code> package.</p><p>For example, to run a function in a new thread:</p><pre><code class="clojure">(let [t (Thread. (fn []
330357
(println "I am running in a separate thread")))]

cryogen.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 23 Mar 2025 18:42:26 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>
1+
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 08 Jun 2025 12:41:29 -0400</lastBuildDate><generator>clj-rss</generator></channel></rss>

feed.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 23 Mar 2025 18:42:26 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>
1+
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 08 Jun 2025 12:41:29 -0400</lastBuildDate><generator>clj-rss</generator></channel></rss>

0 commit comments

Comments
 (0)