tidylab / decorators

Extend the behaviour of a function without explicitly modifying it
https://tidylab.github.io/decorators/
Other
12 stars 0 forks source link

Add make_immutability decorator #2

Open harell opened 3 years ago

harell commented 3 years ago
Car <- function(model = NA_character_, hp = NA_real_) return(
   data.frame(modek = model, hp = hp)
)

Car <- make_immutability(Car, freez = True)
car <- Car(model = "Mercedes-Benz S-Class", hp = 180)
car$hp <- 200 # fails because object is immutable
harell commented 3 years ago

Why use make_immutability()?

Use cases: