JordyBobs
JordyBobs

Reputation: 137

Remove list from list of lists Clojure

I have a list such as:

(def lst '((a b c) (d e) (f g h)))

I need to create a new list having removed one of the inner lists, I've tried

(remove '(d e) lst)

which returns

java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn

I've also tried

(filter (not= '(d e)) lst)

which returns

java.lang.ClassCastException: null

Upvotes: 0

Views: 447

Answers (2)

Leonid Beschastny
Leonid Beschastny

Reputation: 51500

Both filter and remove functions expect first argument to be a predicate function. You could use partial function to transform operator = into a predicate:

(remove (partial = '(d e)) lst)

Upvotes: 4

sloth
sloth

Reputation: 101162

If you want to use filter, note that the first argument has to be a function, so you could use

(filter #(not= '(d e) %) lst)

That's why you get the ClassCastException.

The same is true for remove. You could also use partial instead of an anonymous function:

(remove (partial = '(d e)) lst)

Upvotes: 4

Related Questions