Logo

Programming-Idioms

History of Idiom 135 > diff from v32 to v33

Edit summary for version 33 by misha:
New Clojure implementation by user [misha]

Version 32

2019-09-27, 20:59:38

Version 33

2020-04-29, 16:39:04

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Code
(let [item :a]
  (loop [done []
         todo [0 :a 2 3 4 :a 2 3 4]]
    (if-let [[x & xs] todo]
      (if (= x item)
        (into done xs)
        (recur (conj done x) xs)))))
Comments bubble
it's up to you to convert result vector back to collection type you actually want.
Doc URL
https://clojuredocs.org/clojure.core/loop