From 9387c8e9a23fd7569ff7f53cd142e7824cbe5e55 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 24 Sep 2013 15:07:47 -0700 Subject: [PATCH] combinators.extras: adding throttle. --- extra/combinators/extras/extras.factor | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extra/combinators/extras/extras.factor b/extra/combinators/extras/extras.factor index 8c6c281c18..4bb67a5835 100644 --- a/extra/combinators/extras/extras.factor +++ b/extra/combinators/extras/extras.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays combinators combinators.smart fry generalizations kernel macros math quotations sequences -sequences.generalizations ; +sequences.generalizations sequences.private system ; IN: combinators.extras : once ( quot -- ) call ; inline @@ -42,3 +42,9 @@ MACRO: cleave-array ( quots -- ) MACRO: smart-plox ( true -- ) [ inputs [ 1 - [ and ] n*quot ] keep ] keep swap '[ _ _ [ _ ndrop f ] smart-if ] ; + +: throttle ( quot millis -- quot' ) + 1,000,000 * '[ + _ nano-count { 0 } 2dup first-unsafe _ + >= + [ 0 swap set-nth-unsafe call ] [ 3drop ] if + ] ; inline