weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

insert-nth: ability to use negative numbers #88

Closed velios closed 8 months ago

velios commented 8 months ago

Hi. First of all thx for great tooling.

(require '[medley.core :as medley])
;; Proposal
(let [coll [1 2 3 4 5]]
         (medley/insert-nth -1 :a coll))
;; Suggests the same result as
(let [coll [1 2 3 4 5]
             coll-len (count coll)]
         (medley/insert-nth (dec coll-len) :a coll))
;; => (1 2 3 4 :a 5)
weavejester commented 8 months ago

I think this might be a little too specific for Medley.

tomdl89 commented 8 months ago

Also this implementation would kill laziness in lazy sequences by trying to count them.

velios commented 8 months ago

That's right, I forgot that the lazy sequence returns there... We'll have to do it the old fashioned way. butlast, last, concat is our friends