Created
December 20, 2014 19:30
-
-
Save doivosevic/603d1f47ccdadba7eb94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
showSTENs :: Int -> [StackTrace] -> String | |
showSTENs tabLen = unlines . showSTENs' 0 . build | |
where | |
showTabs :: Int -> String | |
showTabs numSpaces = replicate numSpaces ' ' | |
showSTENs' :: Int -> [STENode] -> [String] | |
showSTENs' tabs [] = [""] | |
showSTENs' tabs stens = concat $ map showSTEN (groupAndJoin . sort $ stens) | |
where | |
showSTEN (STENode ste []) = [showTabs (tabs * tabLen) ++ show ste] | |
showSTEN (STENode ste stens') = (showTabs (tabs * tabLen) ++ show ste) : (showSTENs' (tabs+1) stens') | |
groupAndJoin :: [STENode] -> [STENode] | |
groupAndJoin stens = map merge (group stens) | |
where | |
merge :: [STENode] -> STENode | |
merge stens@((STENode ste _):rest) = STENode ste (concat . map (\(STENode _ ss) -> ss) $ stens) | |
build :: [StackTrace] -> [STENode] | |
build traces = map buildList traces | |
where | |
buildList :: StackTrace -> STENode | |
buildList trace = foldr makeNewSTENode (STENode (last trace) []) (init trace) | |
makeNewSTENode :: StackTraceElement -> STENode -> STENode | |
makeNewSTENode parent child = STENode parent [child] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment