dropJ n v@(Single _ _) | n == 0 = v
| otherwise = Empty
dropJ n (Append t l r) | n > getSize (size t) = Empty
- | n > (getSize (size (tag l))) =
- dropJ (n - getSize (size (tag l))) r
+ | n > leftSize =
+ dropJ (n - leftSize) r
| otherwise = let lft = dropJ n l in
Append ((tag lft) `mappend` (tag r)) lft r
+ where leftSize = getSize . size . tag $ l
-- 3. take
takeJ :: (Sized b, Monoid b) =>
takeJ n v@(Single _ _) | n == 0 = v
| otherwise = Empty
takeJ n v@(Append t l r) | n > getSize (size t) = v
- | n < getSize (size (tag l)) = takeJ n l
- | otherwise = let rt = takeJ (n - getSize (size (tag l))) r in
+ | n < leftSize = takeJ n l
+ | otherwise = let rt = takeJ (n - leftSize) r in
Append ((tag l) `mappend` (tag rt)) l rt
+ where leftSize = getSize . size . tag $ l