Proposal: unsnoc, unsafeInit and unsafeLast for the bytestring library
Duncan Coutts
duncan.coutts at googlemail.com
Tue Aug 28 22:43:13 CEST 2012
On Tue, 2012-04-03 at 21:48 +0700, Mikhail Vorozhtsov wrote:
> On 04/03/2012 08:50 PM, Simon Meier wrote:
> > 2012/4/3 Duncan Coutts<duncan.coutts at googlemail.com>:
> [snip]
> > @mikkhail: Note that at least the runtime for
> > Data.ByteString.Lazy.Char8 is wrong. It should be O(n/c) instead of
> > O(1).
> Fixed.
Ok, I've applied this but with a simpler implementation of unsnoc for
lazy bytestrings.
The proposed implementation tries to work using a single traversal of
the list of chunks, but it doesn't actually achieve this since it builds
a chain of closures that's equivalent to the list of chunks. Doing it by
accumulating and reversing would be equivalent. Given that we cannot
actually avoid making two traversals I've gone for the simplest
implementation: just call init and last.
Duncan
More information about the Libraries
mailing list