to_l: Promote a function to a 'getter' lens

Description Usage Arguments Examples

Description

Create a getter lens from a function.

Usage

1
to_l(f)

Arguments

f

The function to promote.

Examples

1
2
3
4
5
6
7
8
# 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")

lenses documentation built on May 2, 2019, 8:51 a.m.