开发者

Typed persistent data structure a la Clojure, done in Java?

开发者 https://www.devze.com 2022-12-28 23:47 出处:网络
In particular an immutable List with a cons operation would be wel开发者_JS百科come. Dug around a little bit longer. This library probably comes closest: http://functionaljava.googlecode.com/svn/artif

In particular an immutable List with a cons operation would be wel开发者_JS百科come.


Dug around a little bit longer. This library probably comes closest: http://functionaljava.googlecode.com/svn/artifacts/2.22/javadoc/index.html . I would imagine that it would be possible to use Clojure's collection classes directly, but I'm not sure if would feel all that natural. (And I don't necessarily need to 'transactional' behaviour.)


There's also a project of "Clojure's data structures modified for use outside of Clojure" at: https://github.com/krukow/clj-ds


I've written a bunch of persistent data structures in Java. My "PersistentList" is pretty close to what you want.

http://code.google.com/p/mikeralib/source/browse/trunk/Mikera/src/mikera/persistent/PersistentList.java


There are multiple solutions posted in Cons’ing a List in Java. And immutability can be added with:

List l;
...
l = Collections.unmodifiableList(l);


I'm currently using Google Guava. Its collections package has immutable variants for lists, maps, sets, amongst others. The code is easy to use and of high quality.

However, because of implementation details, efficiently consing to a list might not be possible.

0

精彩评论

暂无评论...
验证码 换一张
取 消