Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-31 Thread Michael Gardner
On Jul 31, 2012, at 12:00 AM, Ben Smith-Mannschott wrote:

 ((some-fn :k1 :k2) m)

Ah, excellent. Yet another hidden gem in clojure I'd somehow overlooked until 
now!

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


Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Michael Gardner
Is there an elegant way to say '(or (:k1 m) (:k2 m)), without repeating m? 
Using a let can be awkward if the expression isn't already wrapped in one; 
'(apply #(or %1 %2) (map m [:k1 :k2])) is similarly bad. Hopefully there's 
something clever I'm missing; any ideas?

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


Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Moritz Ulrich
(some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

On Tue, Jul 31, 2012 at 12:48 AM, Michael Gardner gardne...@gmail.com wrote:
 Is there an elegant way to say '(or (:k1 m) (:k2 m)), without repeating m? 
 Using a let can be awkward if the expression isn't already wrapped in one; 
 '(apply #(or %1 %2) (map m [:k1 :k2])) is similarly bad. Hopefully there's 
 something clever I'm missing; any ideas?

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


Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Aaron Cohen
On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

For even more fun, try (some m [:k1 :k2]) :)

--Aaron

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


Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Michael Gardner
On Jul 30, 2012, at 6:08 PM, Aaron Cohen wrote:

 For even more fun, try (some m [:k1 :k2]) :)

Wow, that's perfect. It even works with string keys! Thanks, guys.

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


Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Ben Smith-Mannschott
On Tue, Jul 31, 2012 at 1:08 AM, Aaron Cohen aa...@assonance.org wrote:
 On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com 
 wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

 For even more fun, try (some m [:k1 :k2]) :)

The flip side of this proposal is:

((some-fn :k1 :k2) m)

Which takes advantage of the fact that keywords can be called as
functions. That means it will only work for keyword keys, but the
upshot is that it will work for arbitrary functions (not just
keywords) and m need not be a map.

See also every-pred, which

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


Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Ben Smith-Mannschott
On Tue, Jul 31, 2012 at 7:00 AM, Ben Smith-Mannschott
bsmith.o...@gmail.com wrote:
 On Tue, Jul 31, 2012 at 1:08 AM, Aaron Cohen aa...@assonance.org wrote:
 On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com 
 wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

 For even more fun, try (some m [:k1 :k2]) :)

 The flip side of this proposal is:

 ((some-fn :k1 :k2) m)

 Which takes advantage of the fact that keywords can be called as
 functions. That means it will only work for keyword keys, but the
 upshot is that it will work for arbitrary functions (not just
 keywords) and m need not be a map.

 See also every-pred, which

((my new truly ergonomic keyboard is taking some getting used to -- this
is the second time I've mashed some keys and ended up sending a gmail
message earlier than intended.))

See also every-pred, which complements some-fn. Oh, and see complement
too. These three correspond to 'or', 'and' and 'not' respectively.

// ben

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