diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-09-26 00:48:26 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-09-26 00:48:26 +0000 |
| commit | c7b754e96714eeeb9d315ee3de402d73a27d47db (patch) | |
| tree | 274792f6cdb60387e9bd4b5b7508463b4228bc4a /lib/kernel/Path.ml | |
| parent | b06d16a2eb0846799b3b039dee989cf1cb258b6a (diff) | |
| parent | 0ec1e8a052305f5246d7cd66e11300cd29bc6d64 (diff) | |
| download | RNT-c7b754e96714eeeb9d315ee3de402d73a27d47db.tar.gz RNT-c7b754e96714eeeb9d315ee3de402d73a27d47db.zip | |
Merge branch 'branch-registration'
Diffstat (limited to 'lib/kernel/Path.ml')
| -rw-r--r-- | lib/kernel/Path.ml | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml index 629a527..b83c9b2 100644 --- a/lib/kernel/Path.ml +++ b/lib/kernel/Path.ml @@ -15,32 +15,44 @@ module Error = struct let path_not_found path = condition "path-not-found" "A given path was not found under the specified object" ("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 lookup handle path = +let walking f g handle path = let rec walk handle = function - | [] -> Ok handle + | [] -> g handle | x::xs -> let open Utilities.Result in let open Protocols in - match Directory.from handle with + let* dir = + Handle.require Directory.from handle + |> Result.map_error Concepts.Condition.(complement ("before-segment" |=| Concepts.Value.String x)) in + let* elem = Directory.find dir x in + match elem 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 + | Some elem -> f x handle (fun () -> walk elem xs) in walk handle path + |> Result.map_error Concepts.Condition.(complement ("path" |=| Concepts.Value.String (to_string path))) + +let lookup = walking (fun _ _ f -> f ()) Result.ok let update handle path key reference value = let open Utilities.Result in + let open Protocols 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 + let* registry = Handle.require Registry.from handle in + Registry.update registry key reference value + +let assoc handle path key value = + let open Utilities.Result in + let open Utilities.Fun in + let open Protocols in + let assoc_on handle key value = + let* a = Handle.require Associative.from handle in + let* a' = Associative.update a key value in + Ok (Handle.from a') + in + walking + (fun key dir f -> f () |> fmap (assoc_on dir key |.| Option.some)) + (fun h -> assoc_on h key value) + handle path |
