Something like this will give you what you want:

 (defn subseqx
      [s start end]
        (cond
          (instance? clojure.lang.IPersistentVector s)
          (subvec s start end)

          (instance? java.lang.String s)
          (subs s start end)

          :else
          (let [slice (drop start (take end s))]
            (cond
             (instance? clojure.lang.IPersistentList s)
             (apply list slice)

             (instance? clojure.lang.PersistentTreeSet s)
             (apply sorted-set slice)

             (instance? clojure.lang.PersistentTreeMap s)
             (apply sorted-map (concat slice))

             :else
             slice))))

And you can add conditions for other kinds of ordered collections if and when a need arises. This is neither simple nor pretty, but an advantage of no-side-effects functional programming is that when you call a pure function you don't need to worry about how simple or pretty might be its internal details.
  --Larry

On 6/27/12 3:24 PM, Warren Lynn wrote:
Thanks, but this does not keep the concrete type.

On Wednesday, June 27, 2012 3:42:25 PM UTC-4, Ulises wrote:

    > I'd forgotten that 'into adds things in the "default" place for
    whatever type you're using, hence the reversal on lists. I'm not
    sure if there's a simple way to get the same type out again while
    preserving order.

    How about:

    (defn sub-seq [start end coll]
      (take (- end start) (drop start coll)))

    U

--
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 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

Reply via email to