On Wed, 2 Apr 2014 14:07:47 -0600
Timothy Baldridge <tbaldri...@gmail.com> wrote:

> I don't know of anything built-in, but this should do the trick:
> 
> (defn remove-first [f [head & tail]]
>   (if (f head)
>       tail
>       (cons head (lazy-seq (remove-first f tail)))))
> 
> Timothy
> 
> 

Thanks. This seems to work for my purposes, although I modified it to
handle the empty vector:

(defn remove-first [f [head & tail]]
  (if (not head) []
  (if (f head)
      tail
      (cons head (lazy-seq (remove-first f tail))))))

This implementation doesn't seem to work on everything that "remove"
works on:

com.example.myapp=> (remove #(= [1 2] %) {1 2 3 4})
([3 4])
com.example.myapp=> (remove-first #(= [1 2] %) {1 2 3 4})
UnsupportedOperationException nth not supported on this type: 
PersistentArrayMap  clojure.lang.RT.nthFrom (RT.java:835)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to