v0.18.1: new avg semantics on empty inputs (emits nil)

This commit is contained in:
Christophe Grand 2018-06-13 23:08:05 +02:00
parent 445419effb
commit 0410484f90
3 changed files with 6 additions and 5 deletions

View file

@ -40,7 +40,7 @@ In `net.cgrand.xforms.io`:
Add this dependency to your project:
```clj
[net.cgrand/xforms "0.16.0"]
[net.cgrand/xforms "0.18.1"]
```
```clj

View file

@ -1,4 +1,4 @@
(defproject net.cgrand/xforms "0.18.0"
(defproject net.cgrand/xforms "0.18.1"
:description "Extra transducers for Clojure"
:url "https://github.com/cgrand/xforms"
:license {:name "Eclipse Public License"

View file

@ -59,9 +59,10 @@
([^doubles acc] (when acc (/ (aget acc 1) (aget acc 0))))
([acc x] (avg acc x 1))
([^doubles acc x w] ; weighted mean
(doto (or acc #?(:clj (double-array 3) :cljs #js [0.0 0.0]))
(aset 0 (+ (aget acc 0) w))
(aset 1 (+ (aget acc 1) (* w x))))))
(let [acc (or acc #?(:clj (double-array 3) :cljs #js [0.0 0.0]))]
(doto acc
(aset 0 (+ (aget acc 0) w))
(aset 1 (+ (aget acc 1) (* w x)))))))
(defn sd
"Reducing fn to compute the standard deviation. Returns 0 if no or only one item."