Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ZSink.splitLines #1384

Merged
merged 2 commits into from Aug 22, 2019
Merged

Add ZSink.splitLines #1384

merged 2 commits into from Aug 22, 2019

Conversation

iravid
Copy link
Member

@iravid iravid commented Aug 11, 2019

No description provided.

@iravid
Copy link
Member Author

iravid commented Aug 11, 2019

Oh this has a bug when \r\n is split across inputs. Don't merge yet.

@iravid
Copy link
Member Author

iravid commented Aug 11, 2019

All done. @vasilmkd could you have a look?

@vasilmkd
Copy link
Contributor

It'll be my pleasure. I'll review it first thing in the morning.

jdegoes
jdegoes previously approved these changes Aug 12, 2019
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

Looks useful! Could be also useful to generalize splitOn(',') or whatever.

/**
* Splits strings on newlines. Handles both `\r\n` and `\n`.
*/
final val splitLines: ZSink[Any, Nothing, String, String, Chunk[String]] =
Copy link
Contributor

Choose a reason for hiding this comment

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

Not to nitpick here, but I see this as a deviation from the previous sinks, which have all been defined with def. AFAIK val creates objects eagerly, and they stay in memory for the duration of the program which references this code. Is that something desirable in this case? I may be completely off base here, I just want to hear the reasoning. Same for every other val, including the ones in Sink.

*/
final val splitLines: ZSink[Any, Nothing, String, String, Chunk[String]] =
new SinkPure[Nothing, String, String, Chunk[String]] {
type State = (Chunk[String], Option[String], Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

On an urelated note, this is probably what the stepless sinks' code will look like after the refactoring. :)

@vasilmkd
Copy link
Contributor

Looks useful! Could be also useful to generalize splitOn(',') or whatever.

Or a predicate function.

@vasilmkd
Copy link
Contributor

This needs a rebase and should be good for merging.

@iravid iravid merged commit 094fdb9 into zio:master Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants