downloadSegment
    :: Counter.Counter
    -> ((Maybe Text, Maybe Text) -> IO PageResult)
    -> (Maybe Text, Maybe Text)
    -> IO ()
downloadSegment itemsCounter nextPage initial = do
    (items,next) <- nextPage initial
    forM_
        items
        (\t ->
              (putStrLn $ "File: " ++ T.unpack (s3ObjectKey t)) >>
              Counter.inc itemsCounter)
    case next of
        Nothing -> return ()
        (Just (start,end)) ->
            downloadSegment itemsCounter nextPage (Just start, end)
downloadSegment
    :: Counter.Counter
    -> ((Maybe Text, Maybe Text) -> IO PageResult)
    -> (Maybe Text, Maybe Text)
    -> IO ()
downloadSegment itemsCounter nextPage initial = do
    (items,next) <- nextPage initial
    forM_
        items
        (\t ->
              (putStrLn $ "File: " ++ T.unpack (s3ObjectKey t)) >>
              Counter.inc itemsCounter)
    case next of
        Nothing -> return ()
        (Just (start,end)) ->
            downloadSegment itemsCounter nextPage (Just start, end)
downloadSegment itemsCounter nextPage initial = do
    (items,next) <- nextPage initial
    forM_
        items
        (\t ->
              (putStrLn $ "File: " ++ T.unpack (s3ObjectKey t)) >>
              Counter.inc itemsCounter)
    case next of
        Nothing -> return ()
        (Just (start,end)) ->
            downloadSegment itemsCounter nextPage (Just start, end)