, for :
def my_function(iline, line, rest_of_lines, **other_args):
do_some_side_effects(iline, line, **other_args)
if rest_of_lines == []:
return <some base case>
increment = 5 if <condition> else 1
return my_function(iline+increment,
rest_of_lines[increment-1],
rest_of_lines[increment:],
**other_args)
, , , None.
- :
other_args = get_other_args(...)
my_function(0, lines[0], lines[1:], **other_args)
, - , , , . do_some_side_effects , .
def my_function(iline, line, rest_of_lines, output, **other_args):
some_value = do_some_side_effects(iline, line, **other_args)
new_output = put_value_in_output(some_value, output)
if rest_of_lines == []:
return new_output
increment = 5 if <condition> else 1
return my_function(iline+increment,
rest_of_lines[increment-1],
rest_of_lines[increment:],
new_output,
**other_args)
other_args = get_other_args(...)
empty_output = get_initial_data_structure(...)
full_output = my_function(0, lines[0], lines[1:], empty_output, **other_args)
, Python - , , , - while.
My advice: use a loop while, although I would like to structure my projects and APIs so that using a recursive functional approach is still efficient and readable. I will also try to avoid side effects within the cycle.