Stream: ideas

Topic: Str.lines


view this post on Zulip Kevin Gillette (Dec 23 2022 at 05:44):

Followup from Advent of Code 2022 feedback:

It would be useful to have a function which splits a string into lines, properly taking into account:

  1. Unifying the behavior of differing line ending sequences: \n (unix), \r\n (windows), and \r (mac classic and perhaps others), though carriage-only endings seem to be rare, and on unix it is used in TUIs to mean "erase current line."
  2. Handling a final line which has a trailing newline sequence (the "line ending" interpretation) as well as a final line without a trailing newline sequence (the "line separator" interpretation).

The signature could be:

lines : Str -> List Str

The elements in the returned list would not contain line endings.

view this post on Zulip Richard Feldman (Dec 23 2022 at 11:35):

Love it! I'd be happy to accept a PR for this :smiley:


Last updated: Jun 16 2026 at 16:19 UTC