Jump to content

Display an outline as a nested table: Difference between revisions

m
Line 2,358:
'''
def go(s):
return wikiTableFromRowscompose(
levels(wikiTableFromRows,
paintedTree(colorSwatch)(levels,
widthMeasuredTreepaintedTree(colorSwatch),
fullDepthTree(widthMeasuredTree,
treeFromOutline(s)fullDepthTree,
)head,
)forestFromLevels,
)indentLevelsFromLines
)(
s.splitlines()
)
return go
Line 2,402 ⟶ 2,403:
 
# ------------------ TREE FROM OUTLINE -------------------
 
# treeFromOutline :: String -> Tree String
def treeFromOutline(s):
'''A tree with the structure of the given outline.'''
return forestFromLevels(
indentLevelsFromLines(
s.splitlines()
)
)[0]
 
 
# indentLevelsFromLines :: [String] -> [(Int, String)]
Line 2,618 ⟶ 2,609:
 
# ----------------------- GENERIC ------------------------
 
# compose :: ((a -> a), ...) -> (a -> a)
def compose(*fs):
'''Composition, from right to left,
of a series of functions.
)[0]'''
def go(f, g):
def fg(x):
return f(g(x))
return fg
return reduce(go, fs, lambda x: x)
 
 
# head :: [a] -> a
def head(xs):
'''The first element of a non-empty list.
'''
return xs[0] if isinstance(xs, list) else next(xs)
 
 
# isSpace :: Char -> Bool
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.