Commit b2c93696 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Change [R.E.to_seq] to use an iterator and check its validity.

parent 308bcbff
......@@ -132,6 +132,9 @@ end) = struct
let move direction it =
jump direction it 1
let is_valid it =
it.v
let get_and_move direction it =
let x = get it in
move direction it;
......@@ -154,9 +157,6 @@ end) = struct
let check _it = ()
let is_valid it =
it.v
let set it x =
if finished it then
raise End
......@@ -921,9 +921,6 @@ module Ephemeral = struct
let of_list d xs =
fresh (P.of_list d xs)
let to_seq direction s =
P.to_seq direction (seq s)
let find_opt direction p s =
P.find_opt direction p (seq s)
......@@ -1010,6 +1007,26 @@ module Ephemeral = struct
end
(* It seems difficult to publish a specification that prevents Monolith from
using the sequence returned by [E.to_seq] after the underlying ephemeral
sequence has been modified. The simplest way of telling Monolith about
this is to give a reference implementation of [to_seq] that uses an
iterator and to ensure that [Monolith.PleaseBackOff] is raised if the
iterator has become invalid. *)
let to_seq direction s =
let it = Iter.create direction s in
let rec produce () =
try
if not (Iter.is_valid it) then
raise Monolith.PleaseBackOff;
let x = Iter.get_and_move direction it in
Seq.Cons (x, produce)
with End ->
Seq.Nil
in
produce
end (* Ephemeral *)
(* -------------------------------------------------------------------------- *)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment