On Oct 14, 11:16 pm, Sean Corfield <seancorfi...@gmail.com> wrote:
> On Fri, Oct 14, 2011 at 5:50 PM, Alan Malloy <a...@malloys.org> wrote:
> > I really liked this one too, though my first draft of it was more like
> > (defn pipe [test f]
> >  (fn [value]
> >    (...)))
> ...
> > fix is basically your pipe, except it takes a series of test/f pairs,
> > and to-fix is my original version, returning a function of x instead
> > of computing on x immediately (this is handy as you can map (to-fix
> > string? read-string) over a collection, for example).
>
> Out of curiosity, why wouldn't you define pipe to take [test f value]
> and then you can map (partial pipe string? read-string) over a
> collection?

As you notice lower, I like this argument-order so that I can chain
operations on values better: (swap! some-atom update-in [:kind] fix
string? keyword) flows very nicely: "Change this atom, updating
its :kind value by converting a string to a keyword if necessary".

But, that map is handy, so we have (to-fix), which is basically a
partial setting all *but* the first arg (tying nicely into what you
ask for in the next paragraph).

>
> > Given accepts only one clause and is "shaped" right for use in ->
> > thread chains, like:
>
> > (-> x
> >    inc
> >    (given even? / 2))
>
> So it's given [value test f & args] yes?

Yeah, mirroring update-in and friends. At the moment given is a macro,
so that args don't have to be evaluated unless the test passes, but
I'm not really happy with that choice: it means you can't use it in
update-in chains like you can use fix. I'd love input about these
sorts of decisions, whether or not it ever gets into clojure proper.

> I'm finding quite often I want a function that's a bit like partial
> but puts the deferred arguments at the beginning of the argument list,
> let's call it impartial (j/k) so you could do:
>
> ((comp (impartial given even? / 2) inc) x)
>
> I know that's contrived but I'm finding #(f % args) common enough that
> something like "impartial" (with a better name, please!) would be
> useful in some sort of contrib library of higher-order functions.

Yeah, I've heard this from a few people. Myself, I don't think I run
into this need very often, but maybe I just have a blind spot for it.

> > If nothing else, I recommend you change the argument order to your
> > pipe function: (defn pipe [value test f]) is clearly the "correct"
> > signature, since it means that (like fix) you can use it in update-in/
> > alter/swap!/-> chains.
>
> Ah, that answers my question above. Interesting point. Argument order
> choices are still something I'm learning new things about all the
> time!
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View --http://corfield.org/
> World Singles, LLC. --http://worldsingles.com/
> Railo Technologies, Inc. --http://www.getrailo.com/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)

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