diff options
Diffstat (limited to 'lib/protocols/Relation.ml')
| -rw-r--r-- | lib/protocols/Relation.ml | 18 |
1 files changed, 18 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) ) |
