+1, `cycleN` is Data.Sequence's corollary of `cycle` in Data.List

On Wed, Mar 11, 2015 at 8:14 AM, David Feuer <david.feuer@gmail.com> wrote:
Yesterday I rewrote `*>` for Data.Sequence (again), using an internal function

cycleN :: Int -> Seq a -> Seq a

The name of the function is based on that of Data.Sequence.iterateN.
cycleN takes a sequence and cycles it as many times as requested:

cycleN 0 $ fromList [1,2] = []
cycleN 5 $ fromList [1,2] = [1,2,1,2,1,2,1,2,1,2]

The function is written to maximize sharing in the result sequence and
to minimize construction time. Specifically, cycleN n xs should take
something like O(|xs| + log n) space (of which all but O(log |xs| +
log n) is shared with the structure of xs) and O(log |xs| + log n)
time.

With current (on GitHub) Data.Sequence exports, the only way to get
this functionality with these time and space bounds is to combine
replicate with *> :

cycleN n xs = replicate n () *> xs

This strikes me as a bit unpleasant.

David
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



--
Love in Jesus Christ, John Alfred Nathanael Chee
http://www.biblegateway.com/
http://web.cecs.pdx.edu/~chee/