Sort an outline at every level: Difference between revisions

→‎{{header|Haskell}}: Followed the lead of Wren – labelled each output section.
m (added some related tasks)
(→‎{{header|Haskell}}: Followed the lead of Wren – labelled each output section.)
Line 141:
foldTree (\x xs -> Node x (L.sortBy cmp xs)) (Node "" forest)
in Right $ outlineFromForest (<>) indentUnit sortedForest
 
 
--------------------------- TESTS --------------------------
main :: IO ()
main =
mapM_ (T.putStrLn . (<> "\n")) $
concat $
[ \(comparatorLabel, cmp) ->
either(\kv id id . sortedOutline cmp <$->
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
Line 262 ⟶ 271:
[ s
| x <- textLines
, s <- [T.takeWhile isSpace x]
, 0 /= T.length s ]</lang>
</lang>
{{Out}}
<pre>Four-spaced (A -> Z):
<pre>alpha
 
<pre>alpha
epsilon
iota
Line 277 ⟶ 289:
mu
 
 
Tabbed (A -> Z):
 
alpha
Line 291 ⟶ 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
Line 307 ⟶ 327:
epsilon
 
 
Tabbed (Z -> A):
 
zeta
Line 321 ⟶ 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>
 
=={{header|Wren}}==
9,655

edits