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

Add a @stop or @exit flag #26

Open
pdeffebach opened this issue Apr 9, 2021 · 2 comments
Open

Add a @stop or @exit flag #26

pdeffebach opened this issue Apr 9, 2021 · 2 comments

Comments

@pdeffebach
Copy link
Contributor

One thing that might be nice is to add a flag for exiting the @chain block.

One workflow I use at the REPL is to have a big block that I add to a bunch. But if I wrote a bug that is an an intermediate location, I want to be able to go to that spot.

here is a big block

julia> df = @chain begin 
       map(1:10) do i
           @addnt begin 
               @add apartment_id = rand(1:4)
               @add move_date = rand(dates)
               @add action_type = rand(["move_in", "move_out"])
           end
       end
       DataFrame
       @aside begin 
           move_ins = DataFrame(apartment_id = [1, 2, 3, 4], move_date = Date(2010, 01, 01), action_type = fill("move_in", 4))
       end
       vcat(move_ins, _)
       @orderby :apartment_id :move_date
       @transform diff_from_action = ifelse.(:action_type .== "move_in", 1, -1)
       groupby(:apartment_id) 
       @transform num_people_in_apartment_after_action = cumsum(:diff_from_action)
       groupby(:apartment_id)
       @transform cols(AsTable) = begin 
           @addnt begin 
               @add start_dates = :move_date
               @add end_dates = lead(:move_date)
           end
       end
       end

What if I think I created diff_from_action wrong? To get to the the chain at exactly that place, I would have to delete or comment out a lot of stuff. Or add an end and face a bunch of errors.

But if I could just add an @exit flag right after the diff_from_action command, I could just forget about all the stuff after.

This would solve one thing that made me hesitant about @chain earlier. One benefit of the %>% in dplyr was that it was easy to break out of the chain and return what you wanted.

@EconometricsBySimulation

I think this is a good idea. I wonder if it needs to be a little more obvious than just @exit but maybe @EXIT or something so that looking through a chain with an early break one can immediately spot that it has been interrupted for debugging purposes. I suppose such a feature might be programmatically used for flow control. Something like ((sum(_.A) > x) && @exit).

@pfarndt
Copy link

pfarndt commented Aug 9, 2021

Wouldn't @break be a better name for such an action? @exitseems to be a bit too much in the context of similarly named functions in julia.

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

No branches or pull requests

3 participants