MCPcopy Create free account
hub / github.com/microsoft/typescript-go / ForEachAncestorDirectory

Function ForEachAncestorDirectory

internal/tspath/path.go:1066–1081  ·  view source on GitHub ↗
(directory string, callback func(directory string) (result T, stop bool))

Source from the content-addressed store, hash-verified

1064}
1065
1066func ForEachAncestorDirectory[T any](directory string, callback func(directory string) (result T, stop bool)) (result T, ok bool) {
1067 for {
1068 result, stop := callback(directory)
1069 if stop {
1070 return result, true
1071 }
1072
1073 parentPath := GetDirectoryPath(directory)
1074 if parentPath == directory {
1075 var zero T
1076 return zero, false
1077 }
1078
1079 directory = parentPath
1080 }
1081}
1082
1083func ForEachAncestorDirectoryPath[T any](directory Path, callback func(directory Path) (result T, stop bool)) (result T, ok bool) {
1084 return ForEachAncestorDirectory(string(directory), func(directory string) (T, bool) {

Calls 2

GetDirectoryPathFunction · 0.85
callbackStruct · 0.50

Tested by

no test coverage detected