lenses icon indicating copy to clipboard operation
lenses copied to clipboard

Filepath lenses

Open cfhammill opened this issue 5 years ago • 0 comments

I was oggling r-lib/fs today and my goodness would filesystem lenses be amazing.

ext_l <- lens(view = fs::path_ext, set = fs::path_ext_set)
dirn_l <- lens(view = dirname, set = function(d, x){
  mapply(function(dir, rpl, pth) sub(dir, rpl, pth, fixed = TRUE)
    , dirname(d), x, d, SIMPLIFY = FALSE) 
})

with

  • [ ] basename
  • [ ] path_rel/path_abs
  • [ ] path2list/list2path

left as an exercise for the reader

cfhammill avatar Oct 05 '18 19:10 cfhammill