diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-20 11:20:26 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-20 11:20:26 -0400 |
commit | ef69dc58760232c75b55e91d405116aa5ed03d51 (patch) | |
tree | f43b7050486909382c052af835cf5def89d184ef /src/clojure/contrib/str_utils2.clj | |
parent | 54a19a97e34c04dd7f9410e7683b13c240241458 (diff) |
str_utils2.clj: added partial, with tests
Alternate definition of partial for fns that take their
primary argument first.
Diffstat (limited to 'src/clojure/contrib/str_utils2.clj')
-rw-r--r-- | src/clojure/contrib/str_utils2.clj | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/clojure/contrib/str_utils2.clj b/src/clojure/contrib/str_utils2.clj index 1fbd030d..9a1ea9f7 100644 --- a/src/clojure/contrib/str_utils2.clj +++ b/src/clojure/contrib/str_utils2.clj @@ -30,7 +30,7 @@ http://github.com/francoisdevlin/devlinsf-clojure-utils/"} clojure.contrib.str-utils2 (:refer-clojure :exclude (take replace drop butlast partition - contains? get repeat reverse)) + contains? get repeat reverse partial)) (:import (java.util.regex Pattern))) @@ -317,6 +317,19 @@ [re coll] (filter (fn [x] (re-find re (str x))) coll)) +(defn partial + "Like clojure.core/partial for functions that take their primary + argument first. + + Takes a function f and its arguments, NOT INCLUDING the first + argument. Returns a new function whose first argument will be the + first argument to f. + + Example: (str-utils2/partial str-utils2/take 2) + ;;=> (fn [s] (str-utils2/take s 2))" + [f & args] + (fn [s & more] (apply f s (concat args more)))) + ;;; WRAPPERS |