Data.Sequence
has takeWhileR
and dropWhileR
for efficient deconstruction of Seq
s from the right. However, takeR
, dropR
and splitAtR
are conspicuously absent. take
and drop
are implemented in terms of splitAt
. So, do finger trees not admit an efficient splitAtR
or was this functionality not included for some other reason?
(Separate but somewhat related question: Would a naive dropR
implementation in terms of viewR
perform decently well?)
This question is based on containers-0.5.6.3
.
length
is O(1), so splitAt
suffices to define everything you need, in an efficient way.
splitAtR i s = splitAt (length s - i) s
takeR i s = snd $ splitAtR i s
dropR i s = fst $ splitAtR i s
According to the docs, splitAt
costs O(log(min(i,length s-i)))
, so by symmetry splitAtR
costs the same (just an additional +O(1)
, which we can neglect).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With