Hmmm...  that's pretty clever.  Well done.

Well, if we're gonna play golf :)

(def & comp)
(def p partial)

;;I like this because the amount of white spaces tells me something
;;Almost Pythonesque
(map (& (p map (& (p str2/drop 2)
                  (p str2/take 5)))
        (p str2/split #"\t"))
        (split #"[\r\n]" a-string))

Now, I have a really, really, really strong bias towards functional
composition over ->.  I think it mostly has to do with re-using
existing functionality in core.

As a second example, I have a filtering function that tests a string
for a prefix in.

;;We have a "Smart" part numbering system at my work
;;This uses the format in of a part number to test if is a designed
part.
;;123 parts designate standard hardware
(def designed? (& not #{"123"} (p str2/take 3)))

(filter (designed? :part-number) db-result)

So, my main point is to favor composition/partial in order to re-use
map, filter, etc.

Okay, enough from me on this.

On Aug 19, 9:26 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> On Aug 19, 5:16 pm, Sean Devlin <francoisdev...@gmail.com> wrote:
>
> > However, over time I found this signature did not work well with my
> > code.  Often I would write something like this
>
> > (map (comp (partial map (comp   #(str2/drop % 2)
> >                                 #(str2/take % 5)))
> >                 #(str2/split % #"\t"))
> >         (split a-string #"[\n\r]"))
>
> > This felt a little forced, and the methods don't compose very well.
>
> On the other hand, here's another way of writing the above, using ->
> with some added helpers:
>
>     (defn each [coll f]
>       (map f coll))
>
>     (defmacro each-> [coll & body]
>       `(each ~coll (fn [x#] (-> x# ~...@body))))
>
>      (-> a-string
>          (str2/split #"[\n\r]")
>          (each-> (str2/split #"\t")
>                  (each-> (str2/take 5)
>                          (str2/drop 2))))
>
> -SS
--~--~---------~--~----~------------~-------~--~----~
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