diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
| commit | 584fbca6d920e9a9f91d451667f9380714ac2175 (patch) | |
| tree | a163b916a6f8cb550c8b38ceb01ab01558687a40 /lib/kernel/Path.ml | |
| parent | c7b754e96714eeeb9d315ee3de402d73a27d47db (diff) | |
| download | RNT-584fbca6d920e9a9f91d451667f9380714ac2175.tar.gz RNT-584fbca6d920e9a9f91d451667f9380714ac2175.zip | |
dune fmt
Diffstat (limited to '')
| -rw-r--r-- | lib/kernel/Path.ml | 36 | ||||
| -rw-r--r-- | lib/kernel/Path.mli | 19 |
2 files changed, 35 insertions, 20 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml index b83c9b2..f34abe2 100644 --- a/lib/kernel/Path.ml +++ b/lib/kernel/Path.ml @@ -1,38 +1,42 @@ type t = string list let this = [] -let (@/) x y = x::y +let ( @/ ) x y = x :: y let to_string path = path |> List.map (fun x -> - let str = BatString.replace ~str:x ~sub:"^" ~by:"^^" |> snd in - BatString.replace ~str ~sub:"/" ~by:"^/" |> snd) + let str = BatString.replace ~str:x ~sub:"^" ~by:"^^" |> snd in + BatString.replace ~str ~sub:"/" ~by:"^/" |> snd ) |> BatIO.to_string (BatList.print ~first:"/" ~last:"" ~sep:"/" BatString.print) module Error = struct open Concepts.Condition - 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 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)) end let walking f g handle path = let rec walk handle = function | [] -> g handle - | x::xs -> - let open Utilities.Result in - let open Protocols in - 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 elem -> f x handle (fun () -> walk elem xs) + | x :: xs -> ( + let open Utilities.Result in + let open Protocols in + 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 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))) + |> Result.map_error + Concepts.Condition.(complement ("path" |=| Concepts.Value.String (to_string path))) let lookup = walking (fun _ _ f -> f ()) Result.ok diff --git a/lib/kernel/Path.mli b/lib/kernel/Path.mli index ece0615..198ef83 100644 --- a/lib/kernel/Path.mli +++ b/lib/kernel/Path.mli @@ -1,9 +1,20 @@ type t val this : t -val (@/) : string -> t -> t - +val ( @/ ) : string -> t -> t 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 -val assoc : Protocols.Handle.t -> t -> string -> Protocols.Handle.t option -> (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 + +val assoc : + Protocols.Handle.t -> + t -> + string -> + Protocols.Handle.t option -> + (Protocols.Handle.t, Concepts.Condition.condition) result |
