From 0410484f906c348b73a99f4b06b65962a425b164 Mon Sep 17 00:00:00 2001 From: Christophe Grand Date: Wed, 13 Jun 2018 23:08:05 +0200 Subject: [PATCH] v0.18.1: new avg semantics on empty inputs (emits nil) --- README.md | 2 +- project.clj | 2 +- src/net/cgrand/xforms/rfs.cljc | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 19402cb..03f9d4e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/project.clj b/project.clj index 43e9cce..66ed108 100644 --- a/project.clj +++ b/project.clj @@ -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" diff --git a/src/net/cgrand/xforms/rfs.cljc b/src/net/cgrand/xforms/rfs.cljc index 4a18a85..7635912 100644 --- a/src/net/cgrand/xforms/rfs.cljc +++ b/src/net/cgrand/xforms/rfs.cljc @@ -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."