Sort an outline at every level: Difference between revisions

Content added Content deleted
m (added some related tasks)
(→‎{{header|Haskell}}: Followed the lead of Wren – labelled each output section.)
Line 141: Line 141:
foldTree (\x xs -> Node x (L.sortBy cmp xs)) (Node "" forest)
foldTree (\x xs -> Node x (L.sortBy cmp xs)) (Node "" forest)
in Right $ outlineFromForest (<>) indentUnit sortedForest
in Right $ outlineFromForest (<>) indentUnit sortedForest



--------------------------- TESTS --------------------------
--------------------------- TESTS --------------------------
main :: IO ()
main :: IO ()
main =
main =
mapM_ (T.putStrLn . (<> "\n")) $
mapM_ T.putStrLn $
concat $
concat $
[ \cmp ->
[ \(comparatorLabel, cmp) ->
either id id . sortedOutline cmp <$>
(\kv ->
let section = headedSection (fst kv) comparatorLabel
[spacedOutline, tabbedOutline, confusedOutline, raggedOutline]
in (either (section . (" -> " <>)) section . sortedOutline cmp . snd)
kv) <$>
[ ("Four-spaced", spacedOutline)
, ("Tabbed", tabbedOutline)
, ("First unknown type", confusedOutline)
, ("Second unknown type", raggedOutline)
]
] <*>
] <*>
[("(A -> Z)", comparing rootLabel), ("(Z -> A)", flip (comparing rootLabel))]
-- Two lexical sort comparators: AZ and ZA

[comparing rootLabel, flip (comparing rootLabel)]
headedSection :: T.Text -> T.Text -> T.Text -> T.Text
headedSection outlineType comparatorName x =
T.concat ["\n", outlineType, " ", comparatorName, ":\n\n", x]


spacedOutline, tabbedOutline, confusedOutline, raggedOutline :: T.Text
spacedOutline, tabbedOutline, confusedOutline, raggedOutline :: T.Text
Line 262: Line 271:
[ s
[ s
| x <- textLines
| x <- textLines
, s <- [T.takeWhile isSpace x]
, s <- [T.takeWhile isSpace x]
, 0 /= T.length s ]</lang>
, 0 /= T.length s ]
</lang>
{{Out}}
{{Out}}
<pre>Four-spaced (A -> Z):
<pre>alpha

alpha
epsilon
epsilon
iota
iota
Line 277: Line 289:
mu
mu



Tabbed (A -> Z):


alpha
alpha
Line 291: Line 305:




First unknown type (A -> Z):
Mixed indent characters used: "\t "

-> Mixed indent characters used: "\t "

Second unknown type (A -> Z):

-> Inconsistent indent depths: [4,3,8,9,8,4,4,4,4]


Four-spaced (Z -> A):
Inconsistent indent depths: [4,3,8,9,8,4,4,4,4]


zeta
zeta
Line 307: Line 327:
epsilon
epsilon



Tabbed (Z -> A):


zeta
zeta
Line 321: Line 343:




First unknown type (Z -> A):
Mixed indent characters used: "\t "

-> Mixed indent characters used: "\t "

Second unknown type (Z -> A):


Inconsistent indent depths: [4,3,8,9,8,4,4,4,4]</pre>
-> Inconsistent indent depths: [4,3,8,9,8,4,4,4,4]</pre>


=={{header|Wren}}==
=={{header|Wren}}==