tags:

views:

97

answers:

1

I have the a list in clojure, and (due to the underlying java library) must modify the list (using the iterator's remove method). Is there a more elegant way to get this effect in closure than writing a destructive equivalent of (map fn seq)?

+3  A: 

Clojure lists are immutable so if you need a mutable list it's always possible to use one that Java provides.

For example:

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]>
Jonas