Beta

Callchain - Decorators

Description
Loading description...
Decorator
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    <func>.callback should also have an optional parameter n which decides in which order a callback function is invoked. n is completly relative to its anchor and not necessarily to root. If n == 0 its called first, if n == 1 its called secondly and so on. If n > number of callbacks then the callback is appended to the end of the callchain of its anchor.

    How does inserting multiple callbacks with different ns work? Depending on the meaning of n it can mean one of these things:

    • n is the priority of the callback; callbacks are order by n, then register order. This means using callback(1) after many callback(0) will not affect the ones registered with callback(0)
    • n is the order of the callback stack at the moment; callbacks are treated as a list that can be inserted anywhere. This means using callback(1) after many callback(0) will push all registered callback(0) callbacks except the last registered one after this callback

    In the current design it implies the latter (from the default value being n, and n called at number of callbacks), but this design is unhinged and absolutely nightmarish to use.

    Also, note that the test only tests a single use of n = 0, so it doesn't touch any of the scenario above, and both implementations will pass. This needs to be explicitly tested.

  • Voile Avatar

    Random tests have fixed structures with randomized arguments, which is not acceptable. It is very easy to hard code against this (especially since it is the same structure as the sample tests).

  • Voile Avatar

    So now, when the root function is invoked, it passes its result to foo which then passes its result to eggs

    root |> foo |> eggs
    

    The semantics of result passing and arity handling is not defined anywhere. Apparently root can be in any arity, while every callback function must have arity 1 (and every returned result is directly passed to the next function). Having different handling for root and branch nodes is certainly not expected (also technically you can pass around multiple arguments by spreading an array, like in JS), and should be specified.

  • scarecrw Avatar

    Cool kata!

    I would include in the description that parameterless uses of the callback decorator should act the same as if called with n > number of callbacks. Right now it's unclear what order something like the following should produce:

    @callchain
    def root(arg): ...
    
    @root.callback(1)
    def bar(res): ...
    
    @root.callback
    def foo(res): ...