Hi,

Am 08.12.2010 um 23:05 schrieb Surgo:

> That's a fair criticism. I suppose that I'm not necessarily looking
> for specifically String manipulation abstractions (I can just do a
> (.substr "abc" 1) to get "bc" as a String after all), but rather
> looking for an abstraction that takes something that's addressable as
> a sequence and returns it in the same format or type instead of a seq.

Namespaces to the rescue:

(ns your.name.space
  (:refer-clojure :exclude (first rest)))

(defprotocol MySeq
  (first [this])
  (rest [this]))

(extend-protocol MySeq
  String
  (first [this] (.charAt this 0))
  (rest [this] (subs this 1))
  Object
  (first [this] (clojure.core/first this))
  (rest [this] (clojure.core/rest this)))

Now use first and rest as normal. Here some examples:

your.name.space=> (first "abc")
\a
your.name.space=> (rest "abc")
"bc"
your.name.space=> (first [1 2 3])
1
your.name.space=> (rest [1 2 3]) 
(2 3)

Sincerely
Meikel

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