aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-09-17 01:39:06 +0000
committerEstevan Castilho <tevo@riajuu.net>2026-09-17 01:39:06 +0000
commit2ec420d1542ea64978bdd4666a51ec4959f648b7 (patch)
treec75f952a73508cf2fea0a6904c834d341e22897a /lib/kernel
parent2d0ce6252c94cf23477478b35b39466aa120b7cc (diff)
downloadRNT-2ec420d1542ea64978bdd4666a51ec4959f648b7.tar.gz
RNT-2ec420d1542ea64978bdd4666a51ec4959f648b7.zip
Forsake `lookup'`
Diffstat (limited to 'lib/kernel')
-rw-r--r--lib/kernel/Path.ml36
-rw-r--r--lib/kernel/Path.mli3
2 files changed, 20 insertions, 19 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml
index 936704d..629a527 100644
--- a/lib/kernel/Path.ml
+++ b/lib/kernel/Path.ml
@@ -17,28 +17,30 @@ module Error = struct
("path" |=| Concepts.Value.String (to_string path))
let not_a_registry path = condition "not-a-registry" "The specified path did not point to a registry"
+ ("path" |=| Concepts.Value.String (to_string path))
+
+ let not_a_directory path = condition "not-a-directory" "The specified path did not point to a directory"
("path" |=| Concepts.Value.String (to_string path))
end
-let rec lookup handle = function
- | [] -> Ok (Some handle)
- | x::xs ->
- let open Utilities.Result in
- let open Protocols in
- match Protocols.Directory.from handle with
- | None -> Ok None
- | Some dir ->
- let* elem = Directory.find dir x in
- match elem with
- | None -> Ok None
- | Some elem -> lookup elem xs
-
-let lookup' handle path = lookup handle path
- |> Result.map (Option.to_result ~none:(Error.path_not_found path))
- |> Result.join
+let lookup handle path =
+ let rec walk handle = function
+ | [] -> Ok handle
+ | x::xs ->
+ let open Utilities.Result in
+ let open Protocols in
+ match Directory.from handle with
+ | None -> Error (Error.path_not_found path)
+ | Some dir ->
+ let* elem = Directory.find dir x in
+ match elem with
+ | None -> Error (Error.not_a_directory path)
+ | Some elem -> walk elem xs
+ in
+ walk handle path
let update handle path key reference value =
let open Utilities.Result in
- let* handle = lookup' handle path in
+ let* handle = lookup handle path in
let* registry = Protocols.Registry.from handle |> Option.to_result ~none:(Error.not_a_registry path) in
Protocols.Registry.update registry key reference value
diff --git a/lib/kernel/Path.mli b/lib/kernel/Path.mli
index e3eac9c..6a74350 100644
--- a/lib/kernel/Path.mli
+++ b/lib/kernel/Path.mli
@@ -3,7 +3,6 @@ type t
val this : t
val (@/) : string -> t -> t
-val lookup : Protocols.Handle.t -> t -> (Protocols.Handle.t option, Concepts.Condition.condition) result
-val lookup' : Protocols.Handle.t -> t -> (Protocols.Handle.t, Concepts.Condition.condition) result
+val lookup : Protocols.Handle.t -> t -> (Protocols.Handle.t, Concepts.Condition.condition) result
val update : Protocols.Handle.t -> t -> string -> Protocols.Handle.t option -> Protocols.Handle.t option -> (bool, Concepts.Condition.condition) result