-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib.path.subpath.components
: init
#242695
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -336,6 +336,37 @@ in /* No rec! Add dependencies on this file at the top. */ { | |||||
${subpathInvalidReason path}'' | ||||||
) 0 subpaths; | ||||||
|
||||||
/* | ||||||
Split [a subpath](#function-library-lib.path.subpath.isValid) into its path component strings. | ||||||
Throw an error if the subpath isn't valid. | ||||||
Note that the returned path components are also valid subpath strings, though they are intentionally not [normalised](#function-library-lib.path.subpath.normalise). | ||||||
|
||||||
Laws: | ||||||
|
||||||
- Splitting a subpath into components and [joining](#function-library-lib.path.subpath.join) the components gives the same subpath but [normalised](#function-library-lib.path.subpath.normalise): | ||||||
|
||||||
subpath.join (subpath.components s) == subpath.normalise s | ||||||
|
||||||
Type: | ||||||
subpath.components :: String -> [ String ] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I wish we didn't repeat Haskell's mistake. At your discretion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right, it's a problem with dependent types, which hints at the more general problem that the list type is not a list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That just looks like ambiguous notation to me, same as if you wrote There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the b1/b2 distinction was a distraction. a/b2 is the one that's the problem: the list type is not a list, so it shouldn't use the notation of the list literal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I get it now, if both list values and types use the same syntax it's ambiguous and confusing. So using |
||||||
|
||||||
Example: | ||||||
subpath.components "." | ||||||
=> [ ] | ||||||
|
||||||
subpath.components "./foo//bar/./baz/" | ||||||
=> [ "foo" "bar" "baz" ] | ||||||
|
||||||
subpath.components "/foo" | ||||||
=> <error> | ||||||
*/ | ||||||
subpath.components = | ||||||
subpath: | ||||||
assert assertMsg (isValid subpath) '' | ||||||
lib.path.subpath.components: Argument is not a valid subpath string: | ||||||
${subpathInvalidReason subpath}''; | ||||||
splitRelPath subpath; | ||||||
|
||||||
/* Normalise a subpath. Throw an error if the subpath isn't valid, see | ||||||
`lib.path.subpath.isValid` | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's why this was added: #244358 (comment)