This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; What function can I put as FOO here to yield true | |
; Tried: hash-set, conj, concat | |
(defn mergeMatches [propertyMapList] | |
"Take a list of maps and merges them combining values into a set" | |
(reduce #(merge-with FOO %1 %2) {} propertyMapList)) | |
(def in | |
(list | |
{:a 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Example of using a parameter on a constructor. Parameters on methods are used to | |
describe either type relationships between arguments to the method or between the | |
argument and the return type (more common but not possible in a constructor). Here | |
I use the type X to specify that the two args are of the same type. | |
When calling it, specifying the type is optional as it will automatically be | |
inferred. In cases where the incorrect type is inferred (wrong place in shared | |
hierarchy), you can specify it. If there is no common type, you'll get an error | |
at compile time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mapmap | |
"Apply kf and vf to a sequence, s, and produce a map of (kf %) to (vf %)." | |
([vf s] | |
(mapmap identity vf s)) | |
([kf vf s] | |
(zipmap (map kf s) | |
(map vf s)))) | |
(defn mapmapmap | |
"Apply kf and vf to the keys and vals of a map and zip the results." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest test-sub= | |
(are [expected left right] (= expected (sub= left right)) | |
;; prim | |
true 1 1 | |
false 1 2 | |
;; maps | |
true {} {:a 1} | |
false {:a 1} {} | |
true {:a 1} {:a 1} | |
false {:a 1} {:a 2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sub= | |
"Checks that all keys and vals in m1 are in m2 (but m2 can have extra stuff)" | |
[o1 o2] | |
(if (and (map? o1) (map? o2)) | |
(every? identity (map (fn [[k v]] (sub= v (k o2))) o1)) | |
(= o1 o2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def input [{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}]) | |
;; I have some more elegant impls of this but I didn't want to suck in my util lib | |
(defn mod-vals [f m] | |
(reduce-kv (fn [r k v] (assoc r k (map f v))) | |
{} | |
m)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns x | |
(:use [criterium.core])) | |
(defn pre-into [c i] | |
(into [i] c)) | |
(defn dl | |
"Return a difference list for a list" | |
[l] | |
(fn [x] (concat l x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (test) | |
Cleaning JVM allocations ... | |
Warming up for JIT optimisations ... | |
Estimating execution count ... | |
Running with sample-count 60 exec-count 120 reducing results | |
Checking GC... | |
Cleaning JVM allocations ... | |
Finding outliers ... | |
Bootstrapping ... | |
Checking outlier significance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.test) | |
(def numerals {1 "I", | |
4 "IV", | |
5 "V", | |
9 "IX", | |
10 "X", | |
40 "XL", | |
50 "L", | |
90 "XC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mapmap | |
"Apply kf and vf to a sequence, s, and produce a map of (kf %) to (vf %)." | |
([vf s] | |
(mapmap identity vf s)) | |
([kf vf s] | |
(zipmap (map kf s) | |
(map vf s)))) | |
(defn mapmapmap | |
"Apply kf and vf to the keys and vals of a map and zip the results." |
OlderNewer