Browse files

Added topic subsample function.

  • Loading branch information...
1 parent 94f18b2 commit d106e188a4f79eee1ca91fe0e1357b76d1bb6d28 Anthony Cowley committed Sep 26, 2011
Showing with 7 additions and 0 deletions.
  1. +7 −0 Ros/TopicUtil.hs
View
7 Ros/TopicUtil.hs
@@ -376,3 +376,10 @@ topicOn :: (Applicative m, Monad m) =>
topicOn proj inj trans t =
Topic $ do f <- trans
runTopic $ mapM (\x -> inj x `fmap` f (proj x)) t
+
+-- |@subsample n t@ subsamples topic 't' by dropping 'n' elements for
+-- every element produced by the result topic.
+subsample :: Monad m => Int -> Topic m b -> Topic m b
+subsample n = metamorph $ go n
+ where go 0 x = yield x (go n)
+ go i _ = skip (go (i - 1))

0 comments on commit d106e18

Please sign in to comment.