summary refs log tree commit diff
path: root/lib/path
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-07-20 22:31:57 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-07-26 23:29:54 +0200
commit407db583c54245136fe8e73976abadb7eb9fad80 (patch)
tree500161ab7cf65d7a5cb6a559cf85f2873d4b2546 /lib/path
parent4e14f5fee6a68ee5fb56d07e70e86fcfcebdc7d3 (diff)
downloadnixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar.gz
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar.bz2
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar.lz
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar.xz
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.tar.zst
nixpkgs-407db583c54245136fe8e73976abadb7eb9fad80.zip
lib/path/README.md: Justify returning subpaths
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Diffstat (limited to 'lib/path')
-rw-r--r--lib/path/README.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/path/README.md b/lib/path/README.md
index 87e552d120d..89eec18b113 100644
--- a/lib/path/README.md
+++ b/lib/path/README.md
@@ -187,6 +187,27 @@ Decision: All functions remove trailing slashes in their results.
 
 </details>
 
+### Prefer returning subpaths over components
+[subpath-preference]: #prefer-returning-subpaths-over-components
+
+Observing: Functions could return subpaths or lists of path component strings.
+
+Considering: Subpaths are used as inputs for some functions. Using them for outputs, too, makes the library more consistent and composable.
+
+Decision: Subpaths should be preferred over list of path component strings.
+
+<details>
+<summary>Arguments</summary>
+
+- (+) It is consistent with functions accepting subpaths, making the library more composable
+- (-) 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
+  - (+) If necessary, we can still make it faster by adding builtins to Nix
+  - (+) Alternatively if necessary, versions of these functions that return components could later still be introduced.
+- (+) 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.
+  And once we have a list of component strings, `lib.lists` and `lib.strings` can be used to operate on them.
+  For completeness, `lib.path.subpath.join` allows converting the list of components back to a subpath.
+</details>
+
 ## Other implementations and references
 
 - [Rust](https://doc.rust-lang.org/std/path/struct.Path.html)