I have a list, which may contain elements that will compare as equal. I would like a similar list, but with one element removed. So from (:a :b :c :b :d) I would like to be able to “remove” just one :b to get (:a :c :b :d).
The context is a hand in a card game where two decks of standard cards are in play, so there may be duplicate cards but still played one at a time.
I have working code, see below. Are there more idiomatic ways to do this in Clojure?
(defn remove-one [c left right]
(if (= right ())
left
(if (= c (first right))
(concat (reverse left) (rest right))
(remove-one c (cons (first right) left) (rest right)))))
(defn remove-card [c cards]
(remove-one c () cards))
Here are the Scala answers I got a while ago: What is an idiomatic Scala way to "remove" one element from an immutable List?
How about:
Which splits the list at :b and then removes the :b and concats the two lists.