Created
January 21, 2021 11:51
-
-
Save Torvaney/e500fefb2c676a7f8a03911456a5070a to your computer and use it in GitHub Desktop.
This file contains 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
# From: https://twitter.com/dirk_sch/status/1352194126654148618 | |
library(purrr) | |
library(testthat) | |
fn <- function(xs) { | |
if (!is_list(xs) | length(xs) < 2) | |
return(xs) | |
f_xs <- map(xs, fn) | |
exec(f_xs[[1]], !!!f_xs[2:length(f_xs)]) | |
} | |
expect_equal(fn(list(`+`, 1, list(`*`, 2, 2))), 5) | |
expect_equal(fn(list()), list()) | |
expect_equal(fn(42), 42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment