Functional Data Structures in Java

2019-02-04 18:40发布

Does the Java standard library have any functional data structures, like immutable Sets, Lists, etc., with functional update?

10条回答
叼着烟拽天下
2楼-- · 2019-02-04 19:18

Functional java has Sets, Lists and more interesting abstractions.

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-04 19:21

It's always nice to see Google Collections plugged, but no, we do not have this. I don't know of any Java library that does. Inside Google, we implemented some functional List structures, and guess what? No one uses them. So they aren't likely to become open-sourced any time soon.

查看更多
▲ chillily
4楼-- · 2019-02-04 19:23

You don't need scala. Just pass your collection into:

java.util.Collections.unmodifiableCollection(/* Collection<? extends T> c */);
java.util.Collections.unmodifiableSet(Set s);
java.util.Collections.unmodifiableMap(Map m);
java.util.Collections.unmodifiableList(List l);

I just saw this from another SO question:

Google's ImmutableSet

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSet.html

from the docs:

Unlike Collections.unmodifiableSet(java.util.Set), which is a view of a separate collection that can still change, an instance of this class contains its own private data and will never change. This class is convenient for public static final sets ("constant sets") and also lets you easily make a "defensive copy" of a set provided to your class by a caller.

edited to incorporate comment.

查看更多
Deceive 欺骗
5楼-- · 2019-02-04 19:25

Take a look at Google collections.

查看更多
Ridiculous、
6楼-- · 2019-02-04 19:27

I know this is an old question but a bit of searching around tells me that now we have an alternative for Functional Java.

JavasLang looks like an interesting library for declarative programming and functional data structures in Java.

I haven't compared it with Functional Java in terms of ease of use and performance, but I'd love to get any pointers on that.

查看更多
beautiful°
7楼-- · 2019-02-04 19:34

If you are interested in collections manipulation in a functional style give a look to lambdaj

查看更多
登录 后发表回答