Hi, Alexandru. If you just need more performance on vectors only, there are the core functions mapv, filterv, and subvec (O(1), which can be used to implement takev and dropv). Also, looking at the source of mapv and filterv is instructive, because they use transients internally; you might do that in your solution to get a bit more speed.
If you really need a generic solution where most clj.core functions are performant on your custom data structures, I don't have suggestions, but you can refer to what the experts do: https://github.com/clojure/data.priority-map https://github.com/ztellman?tab=repositories (potemkin, clj-tuple, immutable-bitset, et al) Hope that helps, Leif On Saturday, November 16, 2013 7:01:14 PM UTC-5, Alexandru Nedelcu wrote: > > Hi, > > I'm trying to understand the design of Clojure's collections and one > thing that I find odd is the return of functions operating on sequences. > Like for instance a call such as this will return a lazy-seq and not a > vector: > > (drop 2 [1 2 3 4]) > > The reason why I find it odd is that data-structures have different > characteristics and one may want to use a vector because it supports > efficient indexing and appending to the end. > > Of course, dropping 2 elements like above from a vector is probably > going to have O(n) complexity and thus returning something lazy is more > appropriate. And while there are some operations, like "conj", "pop" and > "peek" that preserve the type, functions such as map and filter also > return lazy-seq. And I worry that the property of the collection you > start with is lost, given that this returns a "cons": > > (conj (filter even? [1 2 3 4 5]) 6) > > So lets say that I want to write a generic function that preserves the > type of that collection. Is something like this idiomatic? > > (defn only-evens [coll] > (into (empty coll) (filter even? coll))) > > Thanks, > > -- > Alexandru Nedelcu > www.bionicspirit.com > > PGP Public Key: > https://bionicspirit.com/key.aexpk > > -- -- 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/groups/opt_out.