Last active
February 3, 2026 20:26
-
-
Save dacr/b4a2934ab5022e7e8d6ca7b71656128c to your computer and use it in GitHub Desktop.
ZIO learning - playing with streams - files list / published by https://github.com/dacr/code-examples-manager #11313cd2-63d7-4125-adcd-5bf489ba9451/c1b635fcfa1383eae73e75b3e563daf9a13f9701
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 streams - files list | |
| // keywords : scala, zio, learning, streams, @testable | |
| // publish : gist | |
| // authors : zio | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 11313cd2-63d7-4125-adcd-5bf489ba9451 | |
| // created-on : 2021-11-05T17:28:20.992Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio:2.0.13" | |
| //> using dep "dev.zio::zio-streams:2.0.13" | |
| // --------------------- | |
| import zio._ | |
| import zio.stream._ | |
| import java.nio.file.{Paths, Files, Path} | |
| object App extends ZIOAppDefault { | |
| def ls(directory: String) = | |
| for | |
| listFromPath <- ZIO.attempt(Path.of(directory)) | |
| files <- ZStream.fromJavaStream(Files.list(listFromPath)).runCollect | |
| yield files | |
| override def run = | |
| for | |
| directory <- ZIO.succeed("/tmp") | |
| results <- ls(directory) | |
| _ <- ZIO.foreach(results)(path => Console.printLine(path)) | |
| yield () | |
| } | |
| App.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment