So the following isn't as clever as the line-noise Don posted, but
should be in the ball-park.
dropFromEnds p = dropWhile p . dropWhileEnd p
dropWhileEnd p bs = take (findFromEndUntil (not p) bs) bs
takeWhileEnd p bs = drop (findFromEndUntil p bs) bs
{- findFromEndUntil is in ByteString.hs,
drtomc:
So the following isn't as clever as the line-noise Don posted, but
should be in the ball-park.
Low level loops are irksome, but guaranteed to be quick :P
dropFromEnds p = dropWhile p . dropWhileEnd p
dropWhileEnd p bs = take (findFromEndUntil (not p) bs) bs
takeWhileEnd p bs =
Hi All,
I notice that Data.ByteString has span and spanEnd. Is there a known
particular reason why dropWhile and takeWhile don't have corresponding
*End functions? If not, what is the protocol for adding them?
cheers,
T.
--
Dr Thomas Conway
[EMAIL PROTECTED]
Silence is the perfectest herald of
drtomc:
Hi All,
I notice that Data.ByteString has span and spanEnd. Is there a known
and break/breakEnd.
particular reason why dropWhile and takeWhile don't have corresponding
*End functions? If not, what is the protocol for adding them?
There's no reason -- we couldn't decide on whether
drtomc:
Well, maybe I shoud be asking a higher level question then.
I have a function
tidy = reverse . dropWhile punk . reverse . dropWhile punk
where
punk = isPunctuation . chr . fromIntegral
which is leading to a significant amount of allocation, and you can see why.
The way
Donald Bruce Stewart wrote:
I'd just manually write a 'tidy' loop (in the Data.ByteString style) (which
would avoid all allocations), since it seems pretty useful.
That would indeed be very useful to have as a library function. I've
pined for Python's strip() string method (removes leading
Thomas Conway wrote:
Well, maybe I shoud be asking a higher level question then.
I have a function
tidy = reverse . dropWhile punk . reverse . dropWhile punk
where
punk = isPunctuation . chr . fromIntegral
which is leading to a significant amount of allocation, and you can see
why.