spebbe / dartz

Functional programming in Dart
MIT License
755 stars 59 forks source link

Example reading lines from big text file #1

Closed jkleiser closed 7 years ago

jkleiser commented 7 years ago

It could be interesting to see an example on how to do efficient text file reads using Free IO and Conveyor, if line-by-line reading is something that Free IO and Conveyor can do efficiently. I'm am not an expert on functional techniques, but I'd like to learn more about it, and I like Dart.

spebbe commented 7 years ago

Hi! I'll try to include a more complex example of file processing in a release soon. For now, the streaming IO example (https://github.com/spebbe/dartz/blob/master/example/streaming_io/example.dart) shows the basics.

Also, please be aware that Conveyor is highly experimental. While it can definitely be used for many real world tasks, it is currently not fully stack safe in all situations. As for efficiency, while it has been improved a lot over time, using Dart's File Streams will often produce faster programs.

Having said that, using Conveyor can greatly improve composability and testability over Stream though, so please try it out!

spebbe commented 7 years ago

I've added a new streaming IO example https://github.com/spebbe/dartz/blob/master/example/streaming_io/example2.dart to the repo. While the actual example doesn't read any big files, the techniques should work equally well for arbitrarily large files. The example does however demonstrate the testability of Free IO, which at least in my mind is superior compared to Dart Streams. Hope it helps!