Alex Rivera | Logout

How can I remove an item from a sequence in Clojure?

Asked 2009-06-02T12:39:02.503
37

First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc.

Second, I assume there are some methods for removal that are structure agnostic; they work on seq interface.

Since sequences are immutable in Clojure, I suspect what you're actually doing is making a cheap copy of the original, only without the original item. This means list comprehension could be used for removal, but I suspect it would be unnecessarily verbose.

Please give some idiomatic examples of the different ways to remove items from Clojure sequences.

Edit
Report

1 Answer

12

Look at the Clojure reference for sequences. filter and remove are what you seek.

answered 2009-06-02T13:24:49.883

Your Answer