Being able to join binary data outside of UTF-8 spec is nice, particularly when working with old stuff that speaks in null terminators.
Haven't had to do this myself but the use case came to mind, and I found at least one <https://github.com/search?q=%2FEnum%5C.join%28.*%2C+%3C%3C0%3E%3E%29%2F&type=code&ref=advsearch> public example. That considered, +1 for supporting binary data in the spec! On Friday, November 10, 2023 at 11:03:58 AM UTC-5 José Valim wrote: > Correct. When it comes to strings, Elixir generally assumes that the > string has been validated before entering the system. If all functions were > to validate they are indeed strings, it will become quite expensive. > > That said, I think your solution of changing the spec is the correct one, > regardless of Unicode. We can give binaries and it will emit binaries back. > So a PR is definitely welcome. > > On Fri, Nov 10, 2023 at 4:35 PM Łukasz Niemier <luk...@niemier.pl> wrote: > >> Currently `Enum.join/2` is using `IO.iodata_to_binary/1` internally to >> join output string. My proposal there is to change that to use >> `:unicode.chardata_to_binary/1` instead, which will allow this function to >> conform to specs. Because currently if we have code like: >> >> s = Enum.join([<<255>>, <<255>>]) >> >> It will output binary that is not string (`String.valid?(s) == false`). >> With `:unicode.chardata_to_binary/1` we could conform to the docs, but it >> would impose some performance hit, because of additional traverse to check >> if all binaries are properly UTF-8 encoded. >> >> So before proposing PR with that change I wanted to consult there - what >> is more expected, correction of the specs (so it would accept any binary >> and will output binary) or it should be changed to check if the resulting >> binary is `String.t()`? >> >> -- >> >> Łukasz Niemier >> luk...@niemier.pl >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to elixir-lang-co...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/C5E0B65F-3373-4980-A04D-351E0EFAEB8D%40niemier.pl >> . >> > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f7c812ef-8470-406f-8d52-378611d48f11n%40googlegroups.com.