aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/str_utils2.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib/str_utils2.clj')
-rw-r--r--src/clojure/contrib/str_utils2.clj15
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