From 314dc05ab0075e14227352eed7522a3853043b74 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 19 Jun 2012 14:23:00 -0700 Subject: [PATCH] math.extras: adding nonzero. --- extra/math/extras/extras-tests.factor | 3 +++ extra/math/extras/extras.factor | 3 +++ 2 files changed, 6 insertions(+) diff --git a/extra/math/extras/extras-tests.factor b/extra/math/extras/extras-tests.factor index 5514932025..aa33351d59 100644 --- a/extra/math/extras/extras-tests.factor +++ b/extra/math/extras/extras-tests.factor @@ -20,3 +20,6 @@ IN: math.extras.test [ 10 [1,b] 2 exponential-moving-average ] unit-test { { 2 5 5 4 3 } } [ { 1 2 5 6 1 4 3 } 3 moving-median ] unit-test + +{ { } } [ { 0 0 } nonzero ] unit-test +{ { 1 2 3 } } [ { 0 1 0 2 0 3 0 } nonzero ] unit-test diff --git a/extra/math/extras/extras.factor b/extra/math/extras/extras.factor index 9bc4d4409c..812de63c47 100644 --- a/extra/math/extras/extras.factor +++ b/extra/math/extras/extras.factor @@ -94,3 +94,6 @@ PRIVATE> : moving-median ( u n -- v ) [ median ] map ; + +: nonzero ( seq -- seq' ) + [ zero? not ] filter ;