aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'lib/protocols')
-rw-r--r--lib/protocols/Directory.mli4
-rw-r--r--lib/protocols/Indexed.ml20
-rw-r--r--lib/protocols/Indexed.mli17
3 files changed, 40 insertions, 1 deletions
diff --git a/lib/protocols/Directory.mli b/lib/protocols/Directory.mli
index 332b1b6..930bda1 100644
--- a/lib/protocols/Directory.mli
+++ b/lib/protocols/Directory.mli
@@ -9,4 +9,6 @@ val make : #implementation -> Handle.protocol
val from : Handle.t -> t Handle.interface option
val list : t Handle.interface -> (string BatFingerTree.t, Concepts.Condition.condition) result
val find : t Handle.interface -> string -> (Handle.t option, Concepts.Condition.condition) result
-val children : Handle.t -> ((string * Handle.t) BatFingerTree.t, Concepts.Condition.condition) result
+
+val children :
+ Handle.t -> ((string * Handle.t) BatFingerTree.t, Concepts.Condition.condition) result
diff --git a/lib/protocols/Indexed.ml b/lib/protocols/Indexed.ml
new file mode 100644
index 0000000..7cf1ea3
--- /dev/null
+++ b/lib/protocols/Indexed.ml
@@ -0,0 +1,20 @@
+module Error = struct
+ open Concepts.Condition
+
+ let not_indexed () =
+ condition "not-indexed" "A handle was expected to carry the indexed protocol and did not" empty
+end
+
+class type implementation = object
+ method indexes : string list
+ method lookup : string -> Concepts.Value.value -> (Handle.t, Concepts.Condition.condition) result
+end
+
+type Handle.protocol += Indexed of implementation
+type t = implementation
+
+let make impl = Indexed (impl :> implementation)
+let from handle = Handle.into handle (function Indexed impl -> Some impl | _ -> None)
+let require handle = from handle |> Option.to_result ~none:(Error.not_indexed ())
+let indexes i = Handle.invoke i (fun o -> o#indexes)
+let lookup i attribute value = Handle.invoke i (fun o -> o#lookup attribute value)
diff --git a/lib/protocols/Indexed.mli b/lib/protocols/Indexed.mli
new file mode 100644
index 0000000..5c8d97d
--- /dev/null
+++ b/lib/protocols/Indexed.mli
@@ -0,0 +1,17 @@
+type t
+
+class type implementation = object
+ method indexes : string list
+ method lookup : string -> Concepts.Value.value -> (Handle.t, Concepts.Condition.condition) result
+end
+
+val make : #implementation -> Handle.protocol
+val from : Handle.t -> t Handle.interface option
+val require : Handle.t -> (t Handle.interface, Concepts.Condition.condition) result
+val indexes : t Handle.interface -> string list
+
+val lookup :
+ t Handle.interface ->
+ string ->
+ Concepts.Value.value ->
+ (Handle.t, Concepts.Condition.condition) result