Functional coverage tree: Difference between revisions
m
→Python: Composition of pure functions: (str.isspace() in lieu of `re`)
m (→{{header|Haskell}}: (Slight generalisation of `indentLevelsFromLines`)) |
m (→Python: Composition of pure functions: (str.isspace() in lieu of `re`)) |
||
Line 1,582:
from itertools import chain, product
from functools import reduce
Line 1,868 ⟶ 1,867:
giving its level of indentation from 0 upwards.
'''
indentTextPairs = list(map(
compose(firstArrow(len), span(
xs
))
Line 1,909 ⟶ 1,907:
return dict(dct, **{k: v})
return lambda v: lambda dct: go(v, dct)
# isSpace :: Char -> Bool
# isSpace :: String -> Bool
'''True if s is not empty, and
contains only white space.
'''▼
return s.isspace()
Line 1,997 ⟶ 2,004:
xs.split(pat) if isinstance(xs, str) else None
)
# splitAt :: Int -> [a] -> ([a], [a])▼
def splitAt(n):
'''A tuple pairing the prefix of length n▼
with the rest of xs.▼
'''
return lambda xs: (xs[0:n], xs[n:])▼
Line 2,007 ⟶ 2,022:
chr(1 + ord(x))
)
▲# splitAt :: Int -> [a] -> ([a], [a])
▲def splitAt(n):
▲ '''A tuple pairing the prefix of length n
▲ with the rest of xs.
▲ '''
▲ return lambda xs: (xs[0:n], xs[n:])
|