<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged wrapper</title>
<link>https://ask.clojure.org/index.php/tag/wrapper</link>
<description></description>
<item>
<title>Consider including a built-in wrapper around `java.net.http.HttpClient` in future versions of Clojure</title>
<link>https://ask.clojure.org/index.php/15129/consider-including-wrapper-around-httpclient-versions-clojure</link>
<description>&lt;p&gt;Java 9 introduced &lt;code&gt;java.net.http.HttpClient&lt;/code&gt;[1] with support for HTTP/1.1, HTTP/2 as well as WebSocket along with other features. It was later standardized in Java 11[2] and has become one of the top picks for Java programs. The latest version of the HTTP client shipped with Java 26 also added support for HTTP/3.[3] &lt;/p&gt;
&lt;p&gt;It would be nice for future versions of Clojure that are based on Java 11+ to include a new namespace with wrapper functions around &lt;code&gt;java.net.http.HttpClient&lt;/code&gt; to make it easier (without all the OOP ceremonies) to work with HTTP in Clojure programs out of the box without relying on any 3rd-party libraries.&lt;/p&gt;
&lt;p&gt;Examples of prior art:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/gnarroway/hato&quot;&gt;https://github.com/gnarroway/hato&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/schmee/java-http-clj&quot;&gt;https://github.com/schmee/java-http-clj&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/babashka/http-client&quot;&gt;https://github.com/babashka/http-client&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://central.sonatype.com/artifact/com.cognitect/http-client&quot;&gt;https://central.sonatype.com/artifact/com.cognitect/http-client&lt;/a&gt;&lt;br&gt;
(upcoming?)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;[1] &lt;a rel=&quot;nofollow&quot; href=&quot;https://openjdk.org/jeps/110&quot;&gt;https://openjdk.org/jeps/110&lt;/a&gt;&lt;br&gt;
[2] &lt;a rel=&quot;nofollow&quot; href=&quot;https://openjdk.org/jeps/321&quot;&gt;https://openjdk.org/jeps/321&lt;/a&gt;&lt;br&gt;
[3] &lt;a rel=&quot;nofollow&quot; href=&quot;https://openjdk.org/jeps/517&quot;&gt;https://openjdk.org/jeps/517&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15129/consider-including-wrapper-around-httpclient-versions-clojure</guid>
<pubDate>Mon, 08 Jun 2026 01:37:14 +0000</pubDate>
</item>
<item>
<title>Immutable wrapper around Java arrays?</title>
<link>https://ask.clojure.org/index.php/13224/immutable-wrapper-around-java-arrays</link>
<description>&lt;p&gt;Are there any immutable wrapper around Java arrays in Clojure, similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://scala-lang.org/api/3.x/scala/collection/immutable/ArraySeq.html&quot;&gt;Scala's ArraySeq&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;What are your thoughts on introducing such a wrapper to Clojure's core?&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13224/immutable-wrapper-around-java-arrays</guid>
<pubDate>Mon, 28 Aug 2023 11:20:27 +0000</pubDate>
</item>
<item>
<title>How to invoke native C-functions in Clojure via JNR-FFI?</title>
<link>https://ask.clojure.org/index.php/9915/how-to-invoke-native-c-functions-in-clojure-via-jnr-ffi</link>
<description>&lt;p&gt;Hi Everyone,&lt;/p&gt;
&lt;p&gt;I want to call native functions in a C-Library from Clojure via &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/jnr/jnr-ffi&quot;&gt;JNR-FFI&lt;/a&gt; without having to write Java code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defproject mypkg
	:dependencies [[org.clojure/clojure &quot;1.10.1&quot;]
				   [com.github.jnr/jnr-ffi &quot;2.2.0&quot;]])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Based on the jnr-ffi examples &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java&quot;&gt;here&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader&quot;&gt;here&lt;/a&gt; a Java wrapper might look like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package blahblah;

public class BlahNative {
	private static int[] intDummy;
	private static double[] doubleDummy;

	public BlahNative() {
	}

	public static native void native_a(char var0, char var1, int var2, int var3, int var4, double[] var7, int var8, int var9);

	public static native void native_b(char var0, char var1, int var2, int var3, int var4, double[] var7, int var8, int var9);

	static {
		lib = LibraryLoader
            .create(LibSodium.class)
            .search(&quot;/usr/local/lib&quot;)
            .search(&quot;/opt/local/lib&quot;)
            .search(&quot;/usr/lib&quot;)
            .search(&quot;/lib&quot;)
            .load(LIBRARY_NAME);
        initializeLibrary(lib);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I presume my Clojure namespace should use the &lt;a rel=&quot;nofollow&quot; href=&quot;http://clojure-doc.org/articles/language/interop.html&quot;&gt;gen-class&lt;/a&gt; feature for implementing Java classes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns mypkg.native
	(:import [jnr.ffi LibraryLoader])
	(:import [jnr.ffi.annotations IgnoreError])
	(:import [jnr.ffi.provider FFIProvider])
    (:gen-class))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;How do I write a &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.baeldung.com/java-native&quot;&gt;native&lt;/a&gt; method in Clojure? In other words, do I even need to specify the method type (as &lt;code&gt;native&lt;/code&gt;) when using Clojure's Java interop features?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After loading the native library I do not know how to access the C-functions in the library. How do I do it?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To avoid reloading the library for every Clojure wrapper function of each C-functions, can I write a method like&lt;/p&gt;
&lt;p&gt; &lt;code&gt;(defn lib (. LibraryLoader load LIBRARY_NAME))&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;and then access the native functions in it?&lt;/p&gt;
&lt;p&gt;I am neither a C nor a Java expert so any guidance will be much appreciated.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9915/how-to-invoke-native-c-functions-in-clojure-via-jnr-ffi</guid>
<pubDate>Fri, 04 Dec 2020 13:57:56 +0000</pubDate>
</item>
</channel>
</rss>