How to curry a … argument by position in R?

后端 未结 2 1319
野性不改
野性不改 2021-01-12 05:25

This may fall under \"you can\'t, and there\'s no reason to anyway,\" but I\'m curious if it\'s possible. At very least, maybe it will be a fun R puzzle.

I was pond

2条回答
  •  春和景丽
    2021-01-12 05:39

    Looks like Curry() pretty effectively hardwires the two argument lists in the opposite order from what you'd like. It's a simple enough function though, that you can just construct its mirror image, and use it instead.

    Curry2 <- function(FUN, ...) {
        .orig = list(...)
        function(...) do.call(FUN, c(list(...), .orig))
    }
    
    catnip <- Curry2( cat, "\n" )
    catnip("hi")
    

提交回复
热议问题