Mutable seqs in clojure

I have a list in clojure, and (due to the java base library) it is necessary to modify the list (using the iterator removal method). Is there a more elegant way to get this effect in closure than writing a destructive equivalent (map fn seq)?

+4
source share
1 answer

Clojure lists are immutable, so if you need a modified list, you can always use the one that Java provides.

For instance:

user=> (import java.util.LinkedList) java.util.LinkedList user=> (def a (list 3 6 1 3)) #'user/a user=> (def b (java.util.LinkedList. a)) #'user/b user=> b #<LinkedList [3, 6, 1, 3]> user=> (.remove b 6) true user=> b #<LinkedList [3, 1, 3]> 
+4
source

All Articles