Last active
May 25, 2024 10:20
-
-
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/cbebd9931ac8f7907baa313523d78f96a3fec2f9
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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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