diff options
author | Clombrong <cromblong@egregore.fun> | 2025-08-15 21:04:04 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-08-15 22:54:43 +0200 |
commit | 0fc9103f770e6135b6f7bc6145b685bb51b89ceb (patch) | |
tree | 764f50c1034f23cc953915508a86b5c211be3f33 /lib/segment.ml | |
parent | d9de994b158a83122aa5623c3a2f848154d8140c (diff) |
feat: rename Wire to Segment
Diffstat (limited to 'lib/segment.ml')
-rw-r--r-- | lib/segment.ml | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/segment.ml b/lib/segment.ml new file mode 100644 index 0000000..ce50f78 --- /dev/null +++ b/lib/segment.ml @@ -0,0 +1,21 @@ +open Lwt.Syntax +open Markup +open Xml + +(** [next stream] is a promise containing a full stanza of the fragments of + [stream]. *) +let next (stream : (signal, async) stream) : (signal, sync) stream Lwt.t = + let traverse_stanza depth fragment = + let depth = match fragment with + | `Start_element _ -> depth + 1 + | `End_element -> depth - 1 + | _ -> depth + in ([fragment], if depth = 0 then None else Some depth) + in transform traverse_stanza 0 stream |> Markup_lwt.load + +(** [get stream] is a promise containing a single Xml element of [stream]. *) +let get (stream : (signal, async) stream) : element Lwt.t = + let* signal = next stream + in match tree signal with + | Some xml -> Lwt.return xml + | None -> Lwt.fail (InvalidStanza (signal |> write_xml |> to_string)) |