A few fs2/zio examples
Run from the repository root, since the examples read testdata/ with relative paths:
sbt "runMain Converter1" # fs2 version
sbt "runMain zioVersion.Converter1" # ZIO versionThe other examples run the same way: WindowedAverage, QueueExample, REPL, EchoServer, each with a zioVersion. counterpart.
🛠️ Built with Scala 3, fs2 3.13 (Cats Effect 3.7) and ZIO 2.1.
sbt test # everything
sbt "testOnly zioVersion.*" # just the ZIO specs- fs2 examples: munit-cats-effect suites in
src/test/scala, withTestControlfor virtual time and a smallFakeConsole - ZIO examples: zio-test specs in
src/test/scala/zioVersion, usingTestClockandTestConsole - The EchoServer tests use real sockets on ports 5556 (fs2) and 5557 (ZIO), so a server on 5555 can keep running
Converts from Fahrenheit file to stdout in Celsius
- 📂 Parses multiple input files
- 🧹 Handles empty lines, comments, non doubles, missing files
- 🔢 Formats to 2 decimal places
- 🏷️ Prepends with a header line
- 🪟 Emits a windowed running average of the last 5 values
- 🏭 Creates stream that emits incrementing int every 100ms to a queue
- 🍽️ Creates stream that reads int from queue and adds int to ref
- ⏱️ Runs both at the same time, terminating after 1 second, printing out the ref sum
- 🔌 Listens for telnet to port 5555, 2 concurrent connections
- 🔁 Echos commands back to user
- 👋 "EXIT" will say "Byebye!" and terminate their connection
- 🛑 "KILLSERVER" will terminate the server
- ⌨️ Also spins up a REPL, so we can kill server cleanly from console, via SignallingRef (fs2) or Promise (ZIO)
- 🛡️ A client that disconnects abruptly only ends its own connection, not the server
- 🐣 A simple REPL example
- 🔁 Echos in the input from stdin
- 🚪 Exits loop upon "KILLSERVER" or EOF signal