groupRequestsOn :: (a -> LogMessage) -> [a] -> [[a]]
groupRequestsOn f = go . dropWhile (not . isRequest . logEntry . f) where
    go (x : xs) = if null respAndRest then [] else thisGroup : go tailMsgs where
        (msg@(LogMessage thId req)) = f x
        (beforeresp, (respAndRest@(~(resp : afterresp)))) = break (myResponse . f) xs
        (myBefore, otherBefore) = partition ((== thId) . logThreadId . f) beforeresp

        thisGroup = x : (myBefore ++ [resp])
        tailMsgs = otherBefore ++ afterresp

        myResponse (LogMessage thId' (LogResponse _)) = thId == thId'
        myResponse _ = False
    go [] = []

    isRequest :: LogEntry -> Bool
    isRequest (LogRequest {}) = True
    isRequest _ = False
groupRequestsOn :: (a -> LogMessage) -> [a] -> [[a]]
groupRequestsOn f = go . dropWhile (not . isRequest . logEntry . f) where
    go (x : xs) = if null respAndRest then [] else thisGroup : go tailMsgs where
        (msg@(LogMessage thId req)) = f x
        (beforeresp, (respAndRest@(~(resp : afterresp)))) = break (myResponse . f) xs
        (myBefore, otherBefore) = partition ((== thId) . logThreadId . f) beforeresp

        thisGroup = x : (myBefore ++ [resp])
        tailMsgs = otherBefore ++ afterresp

        myResponse (LogMessage thId' (LogResponse _)) = thId == thId'
        myResponse _ = False
    go [] = []

    isRequest :: LogEntry -> Bool
    isRequest (LogRequest {}) = True
    isRequest _ = False
groupRequestsOn f = go . dropWhile (not . isRequest . logEntry . f) where
    go (x : xs) = if null respAndRest then [] else thisGroup : go tailMsgs where
        (msg@(LogMessage thId req)) = f x
        (beforeresp, (respAndRest@(~(resp : afterresp)))) = break (myResponse . f) xs
        (myBefore, otherBefore) = partition ((== thId) . logThreadId . f) beforeresp

        thisGroup = x : (myBefore ++ [resp])
        tailMsgs = otherBefore ++ afterresp

        myResponse (LogMessage thId' (LogResponse _)) = thId == thId'
        myResponse _ = False
    go [] = []

    isRequest :: LogEntry -> Bool
    isRequest (LogRequest {}) = True
    isRequest _ = False