Create a getter lens from a function.

to_l(f)

Arguments

f

The function to promote.

Examples

# This wouldn't make sense as a general legal lens, but fine as a `getter` sqrt_l <- to_l(sqrt) iris_root <- index(1) %.% index(1) %.% sqrt_l sqrt(iris[[1]][[1]])
#> [1] 2.258318
iris %>% view(iris_root)
#> [1] 2.258318
tryCatch(iris %>% set(iris_root, 2) , error = function(e) "See, can't do that")
#> [1] "See, can't do that"