Gen: adding a sentinel value (e.g. for fold)?

For some operations, it’d be nice to have a sentinel value (= to be notified when the sequence ends).

This could, e.g. be achieved via function that maps 'a Gen.t to ('a option) Gen.t. The latter sequence would be one element longer than the former.

Is there a built-in way of doing this?

There is peek:

#Gen.(1 -- 5 |> peek |> to_list);;
- : (int * int option) list =
[(1, Some 2); (2, Some 3); (3, Some 4); (4, Some 5); (5, None)]
1 Like

Good point! That should suffice. It gives you a marker for the last element. Thanks!