Create a new lens that views and sets each element of the list.

map_l(l)

Arguments

l

the lens to promote

Details

Uses lapply under the hood for view and mapply under the hood for set. This means that set can be given a list of values to set, one for each element. If the input or update are lists this lens always returns a list. If the input and update are vectors this lens will return a vector.

Examples

(ex <- replicate(10, sample(1:5), simplify = FALSE))
#> [[1]] #> [1] 1 4 2 5 3 #> #> [[2]] #> [1] 3 2 1 4 5 #> #> [[3]] #> [1] 5 1 4 3 2 #> #> [[4]] #> [1] 1 2 5 3 4 #> #> [[5]] #> [1] 2 3 4 1 5 #> #> [[6]] #> [1] 4 1 2 3 5 #> #> [[7]] #> [1] 1 5 4 2 3 #> #> [[8]] #> [1] 3 5 4 1 2 #> #> [[9]] #> [1] 4 2 5 3 1 #> #> [[10]] #> [1] 4 5 3 2 1 #>
view(ex, map_l(index(1)))
#> [[1]] #> [1] 1 #> #> [[2]] #> [1] 3 #> #> [[3]] #> [1] 5 #> #> [[4]] #> [1] 1 #> #> [[5]] #> [1] 2 #> #> [[6]] #> [1] 4 #> #> [[7]] #> [1] 1 #> #> [[8]] #> [1] 3 #> #> [[9]] #> [1] 4 #> #> [[10]] #> [1] 4 #>
set(ex, map_l(index(1)), 11:20)
#> [[1]] #> [1] 11 4 2 5 3 #> #> [[2]] #> [1] 12 2 1 4 5 #> #> [[3]] #> [1] 13 1 4 3 2 #> #> [[4]] #> [1] 14 2 5 3 4 #> #> [[5]] #> [1] 15 3 4 1 5 #> #> [[6]] #> [1] 16 1 2 3 5 #> #> [[7]] #> [1] 17 5 4 2 3 #> #> [[8]] #> [1] 18 5 4 1 2 #> #> [[9]] #> [1] 19 2 5 3 1 #> #> [[10]] #> [1] 20 5 3 2 1 #>