Teacup rim text: Difference between revisions
→Functional Python: Refactored in terms of `until`, as in JS
(→{{header|JavaScript}}: Added a JS draft) |
(→Functional Python: Refactored in terms of `until`, as in JS) |
||
Line 700:
=={{header|Python}}==
===Functional===
Composing generic functions
{{Trans|
<lang python>'''Teacup rim text'''
from os.path import expanduser
Line 735 ⟶ 734:
are found in the lexicon.
'''
def go(
lambda x: x in lexicon,▼
rotations(s)▼
))▼
return lambda w: go(w)▼
return 1 < iLast and until(p)(f)(
# GENERIC -------------------------------------------------▼
def drop(n):▼
▲ def go(xs):
▲ return xs[n:]
return lambda xs: go(xs)▼
▲# GENERIC -------------------------------------------------
# lines :: String -> [String]
Line 787 ⟶ 772:
# rotated ::
def rotated(
'''A list rotated n elements to the right.'''
return
▲ drop(lng - n)(
▲ cycle(xs)
▲ )
#
'''The result of repeatedly applying f until p holds.
The initial seed value is x.
'''
|