myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
myGroupBy f = foldr step [[]]
  where
    step a [[]]                  = [[a]]
    step a (l:ls) | f a (head l) = (a:l):ls
    step a (l:ls)                = [a]:l:ls


-- Ex 06:
myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
myGroupBy f = foldr step [[]]
  where
    step a [[]]                  = [[a]]
    step a (l:ls) | f a (head l) = (a:l):ls
    step a (l:ls)                = [a]:l:ls


-- Ex 06:
myGroupBy f = foldr step [[]]
  where
    step a [[]]                  = [[a]]
    step a (l:ls) | f a (head l) = (a:l):ls
    step a (l:ls)                = [a]:l:ls


-- Ex 06: