diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-07 18:25:43 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-07 18:25:43 -0300 |
| commit | 932e657e38665afa1da1aab549977841abbd9dcf (patch) | |
| tree | b2c0b3d30b7aaab7347300b3932a9f03e4f64f9a /lib/protocols/Relation.ml | |
| parent | cfc641a9bb97c94e5993f895a8bcdf24214adc83 (diff) | |
| download | RNT-932e657e38665afa1da1aab549977841abbd9dcf.tar.gz RNT-932e657e38665afa1da1aab549977841abbd9dcf.zip | |
drop journal in favor of local branch history
Diffstat (limited to '')
| -rw-r--r-- | lib/protocols/Relation.ml | 18 | ||||
| -rw-r--r-- | lib/protocols/Relation.mli | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/protocols/Relation.ml b/lib/protocols/Relation.ml index 3962c9c..b4cc4ec 100644 --- a/lib/protocols/Relation.ml +++ b/lib/protocols/Relation.ml @@ -17,3 +17,21 @@ let make impl = Relation (impl :> implementation) let from handle = Handle.into handle (function Relation impl -> Some impl | _ -> None) let require handle = from handle |> Option.to_result ~none:(Error.not_a_relation ()) let contains i tuple = Handle.invoke i (fun o -> o#contains tuple) + +let read relation = + let open Utilities.Result in + let* schematics = Handle.require Schematics.from relation in + let* description = Schematics.describe schematics in + let* heading = + match description with + | Schematics.Relation heading -> Ok heading + | _ -> Error (Error.not_a_relation ()) + in + let* enumerable = Enumerable.require relation in + let* cursor = Enumerable.enumerate enumerable in + Fun.protect + ~finally:(fun () -> Handle.release cursor) + (fun () -> + let* scan = Cursor.require cursor in + let* tuples = Cursor.drain scan () in + Ok (heading, BatFingerTree.to_list tuples) ) diff --git a/lib/protocols/Relation.mli b/lib/protocols/Relation.mli index be11cc1..87e6ab2 100644 --- a/lib/protocols/Relation.mli +++ b/lib/protocols/Relation.mli @@ -8,3 +8,8 @@ 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 contains : t Handle.interface -> Concepts.Tuple.t -> (bool, Concepts.Condition.condition) result + +(** the heading and tuples of a relation, read whole. *) +val read : + Handle.t -> + (Schematics.relation_description * Concepts.Tuple.t list, Concepts.Condition.condition) result |
