janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

Add String.to_sequence (the standard library has String.to_seq) #160

Closed xojoc closed 9 months ago

xojoc commented 10 months ago

It would be nice to have a String.to_sequence just like we have Array.to_sequence.

It could be as simple as the following snippet:

let string_to_sequence s =
  Sequence.unfold ~init:0 ~f:(fun i ->
      if i >= String.length s then None else Some (String.get s i, i + 1) )

I could submit a PR if this is wanted.