janestreet / base

Standard library for OCaml
MIT License
860 stars 125 forks source link

rfc: String.to_char_list to compliment String.of_char_list #101

Closed cdaringe closed 3 years ago

cdaringe commented 3 years ago

problem

On the concerns of exploding/imploding of strings, Base is asymmetric in that it only offers 1D of utility when breaking-up/pulling-together char lists. That is, String.of_char_list exists, but String.to_char_list does not.

String.split_on_chars is nice, but is intrinsically lossy and doesn't allow to split on the empty string.

Instead, users must opt to author their own impl of string -> char list, a la let explode s = List.init (String.length s) (String.get s).

discussion

Kindly consider improving the dev-ux and discoverability of the String module by adding some API symmetry on the char associated APIs. Specifically, please consider String.to_char_list, or Char.to_list s, etc

bcc32 commented 3 years ago

Ah, sorry for the confusion. Base does offer the function you are looking for, but it's called String.to_list rather than String.to_char_list. There is a weird asymmetry in the name because String.of_char_list is named in analogy to String.of_char instead of just being called of_list.