Permalink
Browse files

'bounds' returns nil if hist is empty

  • Loading branch information...
1 parent 6b6d1bd commit 470246fe9759b09e365d41a086f4cb8ece293a29 @ashenfad ashenfad committed Jan 16, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 src/clj/histogram/core.clj
View
@@ -142,17 +142,17 @@
:target (scrub-target (.getTargetSum result))}))
(defn bounds
- "Returns the bounds of the histogram. An optional parameter may be
- supplied to enable a small buffer to the bounds (true or false -
- default false)."
+ "Returns the bounds of the histogram, nil if the histogram is empty.
+ An optional parameter may be supplied to enable a small buffer to
+ the bounds (true or false - default false)."
([^Histogram hist]
(bounds hist false))
([^Histogram hist buffer?]
- (let [bins (bins hist)
- l-mean (:mean (last bins))
- f-mean (:mean (first bins))]
- (if (and buffer? (second bins))
- {:min (- f-mean (* 1.1 (- (:mean (second bins)) f-mean)))
- :max (+ l-mean (* 1.1 (- l-mean (:mean (last (drop-last bins))))))}
- {:min f-mean
- :max l-mean}))))
+ (when-let [bins (seq (bins hist))]
+ (let [l-mean (:mean (last bins))
+ f-mean (:mean (first bins))]
+ (if (and buffer? (second bins))
+ {:min (- f-mean (* 1.1 (- (:mean (second bins)) f-mean)))
+ :max (+ l-mean (* 1.1 (- l-mean (:mean (last (drop-last bins))))))}
+ {:min f-mean
+ :max l-mean})))))

0 comments on commit 470246f

Please sign in to comment.