Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for loops #431

Open
ZdenekM opened this issue Feb 5, 2021 · 0 comments
Open

Support for loops #431

ZdenekM opened this issue Feb 5, 2021 · 0 comments

Comments

@ZdenekM
Copy link
Member

ZdenekM commented Feb 5, 2021

  • User-defined function can be passed as a parameter to the “for_loop” action (this can be probably made in a generic way, not just for the purpose of cycles).
  • Loop itself is action calling given function, with provided parameters.
  • Depends on Support for project functions #430.

bd7d25f1-f195-43fe-9f2b-505fba040aeb

The code will approximately be like:

def function_1(obj: Generic, idx: int, *, an: Optional[str] = None) -> None:
    obj.hooray(idx, an="action_name_2")

def main():
    ...
    obj.nop()  # just to show that it is there
    ...
    cycles.for_loop(function_1, 0, 10, 1, {"action_name": "a1_for_body", "obj": obj}, an="a1_for")
class Cycles(Generic):

    def for_loop(start: float = 0, stop: float = 10, step: float = 1, loop_body: Callable, loop_body_params: List[ActionParameter], *, an: Optional[str] = None) -> None:
        params_dict = loop_body_params_to_dict(loop_body_params)
        for idx in range(start, stop, step):
            params_dict["idx"] = idx
            loop_body(**params_dict)

Current state: prepared data structures, no support at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant