lib/path/README.md: Justify returning subpaths

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>

+21
+21
lib/path/README.md
··· 187 188 </details> 189 190 ## Other implementations and references 191 192 - [Rust](https://doc.rust-lang.org/std/path/struct.Path.html)
··· 187 188 </details> 189 190 + ### Prefer returning subpaths over components 191 + [subpath-preference]: #prefer-returning-subpaths-over-components 192 + 193 + Observing: Functions could return subpaths or lists of path component strings. 194 + 195 + Considering: Subpaths are used as inputs for some functions. Using them for outputs, too, makes the library more consistent and composable. 196 + 197 + Decision: Subpaths should be preferred over list of path component strings. 198 + 199 + <details> 200 + <summary>Arguments</summary> 201 + 202 + - (+) It is consistent with functions accepting subpaths, making the library more composable 203 + - (-) It is less efficient when the components are needed, because after creating the normalised subpath string, it will have to be parsed into components again 204 + - (+) If necessary, we can still make it faster by adding builtins to Nix 205 + - (+) Alternatively if necessary, versions of these functions that return components could later still be introduced. 206 + - (+) It makes the path library simpler because there's only two types (paths and subpaths). Only `lib.path.subpath.components` can be used to get a list of components. 207 + And once we have a list of component strings, `lib.lists` and `lib.strings` can be used to operate on them. 208 + For completeness, `lib.path.subpath.join` allows converting the list of components back to a subpath. 209 + </details> 210 + 211 ## Other implementations and references 212 213 - [Rust](https://doc.rust-lang.org/std/path/struct.Path.html)