Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 6, 2023 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/b4a2934ab5022e7e8d6ca7b71656128c to your computer and use it in GitHub Desktop.
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/bf8f1d76457e775e499151c1ae7027ce9025e362
// 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.2.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