Last active
February 3, 2026 20:25
-
-
Save dacr/0b10a0d6be3489f3580f7272bf869c9c to your computer and use it in GitHub Desktop.
ZIO learning - playing with nio - list files / published by https://github.com/dacr/code-examples-manager #f9294fae-cc2e-4c4d-a8fb-6623e8857abb/aa7d94e420a3319ac8b1afb4a0dd286ac35299e1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : ZIO learning - playing with nio - list files | |
| // keywords : scala, zio, learning, nio, file, stream, sink, pure-functional, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : f9294fae-cc2e-4c4d-a8fb-6623e8857abb | |
| // created-on : 2021-04-06T17:34:35Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio-nio:2.0.1" | |
| // --------------------- | |
| import zio.* | |
| import zio.stream.* | |
| import zio.nio.file.* | |
| object App extends ZIOAppDefault { | |
| val filesStream = for { | |
| file <- Files.list(Path("/tmp")) | |
| } yield file | |
| // val logic = filesStream.foreach(f => putStrLn(f.toString())) | |
| val logic = for { | |
| result <- filesStream.run(ZSink.collectAll) | |
| _ <- Console.printLine(result.mkString("\n")) | |
| } yield () | |
| override def run = logic | |
| } | |
| // ------------------------------------------------------------- | |
| App.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment