• (partial f & args)
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))

1 Example top

  • (def s1 [[:000-00-0000 "TYPE 1" "JACKSON" "FRED"]
             [:000-00-0001 "TYPE 2" "SIMPSON" "HOMER"]
             [:000-00-0002 "TYPE 4" "SMITH" "SUSAN"]])
    
    (def cols [0 2 3])
    
    (defn f1 
      [s1 col] 
      (map #(get-in s1 [% col] nil) (range (count s1))))
    
    (apply interleave (map (partial f1 s1) cols))
    (:000-00-0000 "JACKSON" "FRED" :000-00-0001 "SIMPSON" "HOMER" :000-00-0002 "SMITH" "SUSAN")
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/str_utils2.clj:326 top

(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))))
Vars in clojure.contrib.str-utils2/partial: apply concat defn fn partial
Used in 0 other vars

Comments top

1 comment(s) for partial.

Where has this gone in the new modular contrib libraries?

Log in to add a comment.