what's a good persistent collections framework for use in java?

前端 未结 13 1413
-上瘾入骨i
-上瘾入骨i 2020-12-01 06:39

By persistent collections I mean collections like those in clojure.

For example, I have a list with the elements (a,b,c). With a normal list, if I add d, my original

13条回答
  •  借酒劲吻你
    2020-12-01 06:50

    totallylazy is a very good FP library which has implementations of:

    • PersistentList: the concrete implementations are LinkedList and TreeList (for random access)
    • PersistentMap: the concrete implementations are HashTreeMap and ListMap
    • PersistentSortedMap
    • PersistentSet: the concrete implementation is TreeSet

    Example of usage:

    import static com.googlecode.totallylazy.collections.PersistentList.constructors.*;
    import com.googlecode.totallylazy.collections.PersistentList;
    import com.googlecode.totallylazy.numbers.Numbers;
    
    ...
    
    PersistentList list = list(1, 2, 3);
    
    // Create a new list with 0 prepended
    list = list.cons(0);
    
    // Prints 0::1::2::3
    System.out.println(list);
    
    // Do some actions on this list (e.g. remove all even numbers)
    list = list.filter(Numbers.odd);
    // Prints 1::3
    System.out.println(list);
    

    totallylazy is constantly being maintained. The main disadvantage is the total absence of Javadoc.

提交回复
热议问题