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_ |
mapM_ T.putStrLn $ |
||
concat $ |
concat $ |
||
[ \cmp -> |
[ \(comparatorLabel, 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) |
|||
] |
|||
] <*> |
] <*> |
||
⚫ | |||
-- Two lexical sort comparators: AZ and ZA |
|||
⚫ | |||
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 ] |
, 0 /= T.length s ] |
||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>Four-spaced (A -> Z): |
|||
⚫ | |||
⚫ | |||
epsilon |
epsilon |
||
iota |
iota |
||
Line 277: | Line 289: | ||
mu |
mu |
||
Tabbed (A -> Z): |
|||
alpha |
alpha |
||
Line 291: | Line 305: | ||
First unknown type (A -> Z): |
|||
⚫ | |||
⚫ | |||
Second unknown type (A -> Z): |
|||
⚫ | |||
Four-spaced (Z -> A): |
|||
⚫ | |||
zeta |
zeta |
||
Line 307: | Line 327: | ||
epsilon |
epsilon |
||
Tabbed (Z -> A): |
|||
zeta |
zeta |
||
Line 321: | Line 343: | ||
First unknown type (Z -> A): |
|||
⚫ | |||
⚫ | |||
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}}== |