Skip to content

Instantly share code, notes, and snippets.

@pingles
Created June 14, 2011 22:08
Show Gist options
  • Save pingles/1026048 to your computer and use it in GitHub Desktop.
Save pingles/1026048 to your computer and use it in GitHub Desktop.
(ns error-example)
(declare ^{:dynamic true} handle-error)
(defn- calculation
[x]
(if (= (mod x 5) 0)
(do (handle-error x)
nil)
x))
(let [errors (atom [])]
(binding [handle-error (fn [x] (swap! errors conj x))]
{:results (doall (remove nil?
(pmap calculation (range 1 200))))
:errors @errors}))
;; {:results (1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26
;; 27 28 29 31 32 33 34 36 37 38 39 41 42 43 44 46 47 48 49 51 52 53
;; 54 56 57 58 59 61 62 63 64 66 67 68 69 71 72 73 74 76 77 78 79 81
;; 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99 101 102 103 104 106
;; 107 108 109 111 112 113 114 116 117 118 119 121 122 123 124 126 127
;; 128 129 131 132 133 134 136 137 138 139 141 142 143 144 146 147 148
;; 149 151 152 153 154 156 157 158 159 161 162 163 164 166 167 168 169
;; 171 172 173 174 176 177 178 179 181 182 183 184 186 187 188 189 191
;; 192 193 194 196 197 198 199), :errors [5 10 15 20 25 30 35 40 45 50
;; 55 60 70 65 75 80 90 85 95 100 110 115 120 125 105 130 135 140 145
;; 150 155 160 165 170 175 185 180 195 190]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment