cmu-delphi / flu-hosp-forecast

1 stars 0 forks source link

Validate or otherwise force arguments to function factories #45

Open brookslogan opened 4 months ago

brookslogan commented 4 months ago

Same as here. [copying below]

See R Inferno 8.3.16. Here's a silly example:

deep_forecaster <- function(x) {
  return (42)
}

make_forecaster_square <- function(forecaster) {
  function(x) {
    forecaster(x) ^ 2
  }
}

my_forecaster <- deep_forecaster
my_forecaster <- make_forecaster_square(my_forecaster)

my_forecaster(4)
#> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Now, we likely/hopefully avoid this by not doing this reassignment. But if we want to package up our function factories into tooling libraries, we should make sure to force all incoming promises --- ideally, by performing validation on the args.