From 8baa58d7683b092d9e27e35d46a6b9ecb61fa4ab Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Wed, 9 Sep 2026 22:15:35 -0300 Subject: path utilities on kernel for lookup on registry --- lib/kernel/Path.ml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lib/kernel/Path.ml') diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml index 803d8cf..cd51efb 100644 --- a/lib/kernel/Path.ml +++ b/lib/kernel/Path.ml @@ -1,17 +1,21 @@ -type t = string list +type t = string BatFingerTree.t -let this = [] -let (@/) x y = x::y +let this = BatFingerTree.empty -let rec lookup handle = function - | [] -> Ok (Some handle) - | x::xs -> - let open Utilities.Result in - let open Protocols in +let of_string s = + String.split_on_char '/' s |> List.filter (fun s -> s <> "") |> BatFingerTree.of_list + +let (@/) segment path = BatFingerTree.cons path segment + +let rec lookup handle path = + let open Utilities.Result in + match BatFingerTree.front path with + | None -> Ok (Some handle) + | Some (rest, segment) -> ( match Protocols.Directory.from handle with | None -> Ok None - | Some dir -> - let* elem = Directory.find dir x in - match elem with + | Some dir -> ( + let* found = Protocols.Directory.find dir segment in + match found with | None -> Ok None - | Some elem -> lookup elem xs + | Some handle' -> lookup handle' rest)) -- cgit v1.2.3