Skip to content

Commit

Permalink
Initial commit of reverse depth
Browse files Browse the repository at this point in the history
  • Loading branch information
aothms committed Jan 28, 2025
1 parent d4e3d34 commit 3255194
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions features/steps/validation_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def handle_then(context, fn, **kwargs):
)
)

def map_then_state(items, fn, context, current_path=[], depth=0, **kwargs):
def map_then_state(items, fn, context, current_path=[], depth=0, current_depth=0, **kwargs):
def apply_then_operation(fn, inst, context, current_path, depth=0, **kwargs):
if inst is None:
return
Expand Down Expand Up @@ -277,13 +277,15 @@ def should_apply(items, depth):
else:
return is_nested(items) and all(should_apply(v, depth-1) for v in items if v is not None)

# debugging:
print(' '*current_depth,current_depth,':',items)

if context.is_global_rule:
return apply_then_operation(fn, [items], context, current_path=None, **kwargs)
elif should_apply(items, depth):
elif depth == current_depth:
return apply_then_operation(fn, items, context, current_path, **kwargs)
elif is_nested(items):
new_depth = depth if depth > 0 else 0
return type(items)(map_then_state(v, fn, context, current_path + [i], new_depth, **kwargs) for i, v in enumerate(items))
elif depth > current_depth:
return type(items)(map_then_state(v, fn, context, current_path + [i], depth, current_depth + 1, **kwargs) for i, v in enumerate(items))
else:
return apply_then_operation(fn, items, context, current_path = None, **kwargs)

Expand Down

0 comments on commit 3255194

Please sign in to comment.