to_l {lenses}R Documentation

Promote a function to a getter lens

Description

Create a getter lens from a function.

Usage

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]])
iris %>% view(iris_root)
tryCatch(iris %>% set(iris_root, 2)
       , error = function(e) "See, can't do that")


[Package lenses version 0.0.3 Index]