Display an outline as a nested table: Difference between revisions
Display an outline as a nested table (view source)
Revision as of 00:03, 6 September 2021
, 2 years ago→Python: Functional
Line 2,358:
'''
def go(s):
return
s.splitlines()▼
)
return go
Line 2,402 ⟶ 2,403:
# ------------------ TREE FROM OUTLINE -------------------
▲ 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.
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
|