weavejester/medley — pull request #7 by james-henderson (2014-05-24 17:04:38+00:00)
Title: Higher order functions

Hi James,

Here's a few additions to Medley that I find myself either wishing for on a regular basis, or duplicating in a number of projects!

`all` and `any` are two macros that take in a list of predicates and return another predicate that returns true if all/any of the passed predicates return true - useful for passing to `filter`/`remove`.

`->%` and `->>%` are maybe a bit more obscure - they're mostly to get around the restriction that you can't nest anonymous functions (of the `#(...)` variety) - e.g. :

```clojure
;; ->% is good for seqs of maps
(let [table [{:a 1 :b [4 12]},
{:a 3 :b [8 35]}]]
(map (->% (update-in [:b] #(map inc %))
(assoc :c 8))
table))

;; -> [{:a 1, :b [5 13], :c 8},
;; {:a 3, :b [9 36], :c 8}]
```
and
```clojure
;; ->>%, on the other hand, is better for nested seqs
(let [results [[3 5 8 12], [6 49 23 18]]]
(map (->>% (map #(nth % 2))
(* 2))

results)

;; -> [24 36]
```

I'm happy to change anything about the PR - names/docstrings/implementations - feedback welcome! Also, if you don't feel they belong in Medley, let me know and I'll release them separately.

Thanks for writing and maintaining Medley btw - we use it in a lot of projects at Likely, especially the `map-keys` and `map-vals` functions (which seem to turn up in almost every other namespace!).

Hope you're keeping well,

James