Why is there no takeR, dropR, or splitAtR data in Data.Sequence?

Data.Sequence has takeWhileR and dropWhileR for efficiently deconstructing Seq right. However, takeR , dropR and splitAtR noticeably absent. take and drop implemented in terms of splitAt . So, fingers do not allow efficient splitAtR or is this feature not enabled for any other reason?

(A separate, but somewhat related question: will the naive implementation of dropR in terms of viewR ?)

This question is based on containers-0.5.6.3 .

+6
source share
1 answer

length is O (1), so splitAt enough to define everything you need in an efficient way.

  splitAtR is = splitAt (length s - i) s takeR is = snd $ splitAtR is dropR is = fst $ splitAtR is 

According to the docs, splitAt costs O(log(min(i,length si))) , so by symmetry splitAtR costs the same thing (just extra +O(1) , which can be neglected).

+8
source

Source: https://habr.com/ru/post/989479/


All Articles