module Ex6 where

import Prelude hiding (foldr)
import Data.Vector 

partitionAt :: (Show a, Ord a) => Vector a -> Int -> (Vector a, a, Vector a)
partitionAt v pivot = let pv = v !? pivot
                          vSplit = remove pivot v  
                          part = foldList pv (remove pivot v)
                          in part 
                      


foldList :: (Show a, Ord a) => Maybe a -> Vector a -> (Vector a, a, Vector a)
foldList Nothing l   = undefined
foldList (Just pv) l = let lists = foldr (\x y ->
                                              case (x >= pv) of
                                                 True -> (fst y, (cons x (snd y)))
                                                 False -> ((cons x (fst y)), snd y) 
                                              ) (Data.Vector.empty, Data.Vector.empty) l 
                           in ((fst lists), pv, (snd lists))   


remove i v = let (l, r) = (Data.Vector.splitAt i v)
             in l Data.Vector.++ (Data.Vector.tail r)       


