This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def decorator(fn): | |
| def f(): | |
| return "dec" + fn() | |
| f.decorated=True | |
| f.original_func = fn | |
| return f | |
| def decorator_override(fn): | |
| def f(): | |
| if fn.decorated: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def decorator(f): | |
| def f_new(): | |
| print "pre" | |
| f() | |
| print "post" | |
| try: | |
| f.decorated | |
| return f | |
| except AttributeError: | |
| f_new.decorated=True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(dplyr) # version 0.4.3 | |
| f1 <- function(x, y) { if (x < 5) y else if (x >= 5) y + 10 } | |
| f2 <- function(x, y) { if (x < 5) y + 0 else if (x >= 5) y + 10 } | |
| d <- data.frame(x=1:10, y=1:10) | |
| d %>% rowwise() %>% mutate(z=f1(x, y)) | |
| # Error: incompatible types, expecting a integer vector | |
| d %>% rowwise() %>% mutate(z=f2(x, y)) | |
| # Source: local data frame [10 x 3] | |
| # Groups: <by row> |
OlderNewer