On Sat, 7 May 2011 12:09:45 -0700 Sean Corfield <seancorfi...@gmail.com> wrote: > Identity on its own isn't really useful - but in combination with > higher-order functions, it can be very indispensible!
Bingo. An HOF accepts a function that filters/mogrifies data before processing it in some way. Sometimes, you *don't* want to have that extra step. There are two ways to do that: one is to have two variants of the HOF - one which uses the function, and one which doesn't (which may mean it's not an HOF). The other is identity. Clojure does both, depending. You can see the first in sort and sort-by, where sort-by uses a keyfn to extract keys from items in the collection. You could just identity for the keyfn to sort by items, but this case is so common it gets it's own function - sort. Similarly, filter takes a predicate to check which items need to be removed. If you just want to remove false values, the appropriate predicate is identity. This case isn't very common, so there's no second version. <mike -- Mike Meyer <m...@mired.org> http://www.mired.org/ Independent Software developer/SCM consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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