aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-09-19 01:32:02 +0000
committerEstevan Castilho <tevo@riajuu.net>2026-09-19 01:32:02 +0000
commit2e8f23c7802e9afb43a0e9846416f93a63a7e592 (patch)
tree54ed10f436ca6d1074e391dd80fb5fdd7516fd1c /lib
parent2e2d7f6a9b116dac2fa20be657c916cb498c1508 (diff)
downloadRNT-2e8f23c7802e9afb43a0e9846416f93a63a7e592.tar.gz
RNT-2e8f23c7802e9afb43a0e9846416f93a63a7e592.zip
Immutable associative collection protocol
Diffstat (limited to 'lib')
-rw-r--r--lib/protocols/Associative.ml16
-rw-r--r--lib/protocols/Associative.mli11
-rw-r--r--lib/protocols/Handle.ml2
-rw-r--r--lib/protocols/Handle.mli1
4 files changed, 30 insertions, 0 deletions
diff --git a/lib/protocols/Associative.ml b/lib/protocols/Associative.ml
new file mode 100644
index 0000000..aa691d0
--- /dev/null
+++ b/lib/protocols/Associative.ml
@@ -0,0 +1,16 @@
+class type implementation = object
+ method update : string -> Handle.t option -> Handle.t option -> (Handle.t, Concepts.Condition.condition) result
+end
+
+type Handle.protocol += Associative of implementation
+
+type t = implementation
+
+let make impl = Associative (impl :> implementation)
+
+let from handle = Handle.into handle (function Associative impl -> Some impl | _ -> None)
+
+let update i key reference value = Handle.invoke i (fun o ->
+ let open Utilities.Result in
+ let* h = o#update key reference value in
+ Handle.require from h)
diff --git a/lib/protocols/Associative.mli b/lib/protocols/Associative.mli
new file mode 100644
index 0000000..6aecca3
--- /dev/null
+++ b/lib/protocols/Associative.mli
@@ -0,0 +1,11 @@
+type t
+
+class type implementation = object
+ method update : string -> Handle.t option -> Handle.t option -> (Handle.t, Concepts.Condition.condition) result
+end
+
+val make : #implementation -> Handle.protocol
+
+val from : Handle.t -> t Handle.interface option
+
+val update : t Handle.interface -> string -> Handle.t option -> Handle.t option -> (t Handle.interface, Concepts.Condition.condition) result
diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml
index 313a3d4..cb78cf2 100644
--- a/lib/protocols/Handle.ml
+++ b/lib/protocols/Handle.ml
@@ -36,6 +36,8 @@ let invoke { handle; interface } f =
let _ = object_of handle in
f interface
+let from { handle; _ } = handle
+
let copy handle =
let o = object_of handle in
if o#reference then
diff --git a/lib/protocols/Handle.mli b/lib/protocols/Handle.mli
index f63bbea..5640b14 100644
--- a/lib/protocols/Handle.mli
+++ b/lib/protocols/Handle.mli
@@ -14,6 +14,7 @@ end
val make : #obj -> t
val into : t -> (protocol -> 'a option) -> 'a interface option
+val from : 'a interface -> t
val invoke : 'a interface -> ('a -> 'b) -> 'b