Proposal: Export cycleN from Data.Sequence

John Alfred Nathanael Chee cheecheeo at gmail.com
Wed Mar 18 21:29:25 UTC 2015


+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 at 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 at 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150318/10bb17a7/attachment.html>


More information about the Libraries mailing list