-
Notifications
You must be signed in to change notification settings - Fork 9
Add example for fs2-data-csv #16
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
Conversation
Adding/removing a field and printing that out? Calculating and printing the max/min/mean for a specific column? |
| * [Circe] and http4s integration | ||
| * [Decline Effect] | ||
| * [Munit Cats Effect] | ||
| * [fs2-data-csv] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this the line you added in another PR? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol I've just realized it's a duplicate
Well this is awkward, I don't know how to do aggregation on columns, I want to print out the mean of the ages column using fs2. Do I use a |
I'll say something like val (a,b) = listOfNumbers.foldLeft((0,0)){ case ((s, n), x) => (s + x, n + 1) }
a/b |
| val meanIO = | ||
| input | ||
| .foldMap(p => (p.age.getOrElse(0), 1)) | ||
| .compile | ||
| .lastOrError | ||
| .map((sum, count) => sum / count) | ||
|
|
||
| input | ||
| .evalTap(p => | ||
| IO.println( | ||
| s"${p.firstName} is taking flight: ${p.flightNumber} to ${p.destination}" | ||
| ) | ||
| ) | ||
| .compile | ||
| .drain >> meanIO.flatMap(mean => | ||
| IO.println(s"The mean age of the passengers is $mean") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is any way to do this in one run I'd love to know!
The only thing I could think of is chucking a IO.println and flatmapping in the foldMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit late on that, but can't you put the evalTap right before the foldMap, and then compile and run
.flatMap { (sum, count) =>
IO.println(s"The mean age of the passengers is ${sum / count}")
}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satabin feel free to propose a neater implementation. Now it should be easier as toolkit contains fs2-data-csv too :D

Anybody else know something more exciting to do than printing out the parsed lines of a CSV?