<div dir="ltr">+1, `cycleN` is Data.Sequence's corollary of `cycle` in Data.List<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 11, 2015 at 8:14 AM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yesterday I rewrote `*>` for Data.Sequence (again), using an internal function<br>
<br>
cycleN :: Int -> Seq a -> Seq a<br>
<br>
The name of the function is based on that of Data.Sequence.iterateN.<br>
cycleN takes a sequence and cycles it as many times as requested:<br>
<br>
cycleN 0 $ fromList [1,2] = []<br>
cycleN 5 $ fromList [1,2] = [1,2,1,2,1,2,1,2,1,2]<br>
<br>
The function is written to maximize sharing in the result sequence and<br>
to minimize construction time. Specifically, cycleN n xs should take<br>
something like O(|xs| + log n) space (of which all but O(log |xs| +<br>
log n) is shared with the structure of xs) and O(log |xs| + log n)<br>
time.<br>
<br>
With current (on GitHub) Data.Sequence exports, the only way to get<br>
this functionality with these time and space bounds is to combine<br>
replicate with *> :<br>
<br>
cycleN n xs = replicate n () *> xs<br>
<br>
This strikes me as a bit unpleasant.<br>
<br>
David<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Love in Jesus Christ, John Alfred Nathanael Chee<br><a href="http://www.biblegateway.com/" target="_blank">http://www.biblegateway.com/</a><br><a href="http://web.cecs.pdx.edu/~chee/" target="_blank">http://web.cecs.pdx.edu/~chee/</a></div>
</div>