Skip to content

Conversation

@andrykonchin
Copy link
Contributor

Changes:

  • added remove_empty parameter for method def each_line(chomp : Bool = true, & : String ->) : Nil
  • added remove_empty parameter for method def each_line(chomp = true)

Closes #15149

@andrykonchin
Copy link
Contributor Author

andrykonchin commented Oct 18, 2025

I am concerned about handling "\n" lines when given chomp: false, so a line is logically "empty" but a String object returned to a user is not.

@ysbaddaden
Copy link
Contributor

The line itself is still empty?

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove_empty applies a filter, chomp defines how the items are presented.
The empty line filter should not be affected by whether non-empty lines end with a NL character or not.

@andrykonchin
Copy link
Contributor Author

The line itself is still empty?

Confusion that may happen is what is filtered with the remove_empty filter - lines or strings as far as "\n" is a non-empty string but an empty line.

It seems logical to apply the filter to lines, that's a "\n" line will be filtered out regardless of the chomp option value. Does is make sense?

@straight-shoota straight-shoota changed the title Remove empty lines from String#each_line Remove empty lines from String#each_line Nov 13, 2025
@straight-shoota straight-shoota added this to the 1.19.0 milestone Nov 13, 2025
@straight-shoota straight-shoota changed the title Remove empty lines from String#each_line Add String#each_line parameter remove_empty Nov 15, 2025
@straight-shoota straight-shoota merged commit b0b1c30 into crystal-lang:master Nov 15, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove empty lines from String#each_line

3 participants