Skip to content

Commit

Permalink
map-difference utility function.
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Mar 23, 2011
1 parent 3db0360 commit 4451cf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/midje/util/form_utils.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
;; -*- indent-tabs-mode: nil -*-

(ns midje.util.form-utils
(:use [midje.util laziness]))
(:use [midje.util laziness]
[clojure.set :only [difference]]))

(defn regex? [thing]
(= (class thing) java.util.regex.Pattern))
Expand Down Expand Up @@ -71,3 +72,6 @@
(map (fn [function arg] (apply function [arg]))
functions arglist))
arglists))

(defn map-difference [bigger smaller]
(select-keys bigger (difference (set (keys bigger)) (set (keys smaller)))))
3 changes: 3 additions & 0 deletions test/midje/util/t_form_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
(hash-map-duplicates-ok :a 1 :b 2) => {:a 1 :b 2}
(hash-map-duplicates-ok :a 1 :b 2 :b 33333) => {:a 1 :b 33333})


(fact "map-difference"
(map-difference {:a 1, :b 2} {:a 1, :c 3}) => {:b 2})

0 comments on commit 4451cf5

Please sign in to comment.