Last active
February 3, 2026 20:22
-
-
Save dacr/4656df99550ae4e22da4d2a4548ff05e to your computer and use it in GitHub Desktop.
ZIO learning - playing with streams - stream of random longs coming from linux secured rng / published by https://github.com/dacr/code-examples-manager #443264aa-9413-4557-9612-053294fdb42b/50b08d733fc9c77e55caee8814302c484914b1ab
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 - stream of random longs coming from linux secured rng | |
| // 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 : 443264aa-9413-4557-9612-053294fdb42b | |
| // created-on : 2021-10-30T23:09:55+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio-streams:2.0.13" | |
| //> using dep "fr.janalyse::zio-worksheet:2.0.13.0" | |
| // --------------------- | |
| import zio.*, zio.stream.*, zio.worksheet.* | |
| import java.nio.file.Paths | |
| val randomNumberStream = | |
| ZStream | |
| .fromPath(Paths.get("/dev/random")) | |
| .grouped(4) | |
| .map(chunk => BigInt(chunk.toArray).toLong) | |
| .filter(_ > 0) | |
| val logic = | |
| for { | |
| randomNumbers <- randomNumberStream.take(500).runCollect // We limit the stream to a finite size... | |
| _ <- ZIO.foreach(randomNumbers)(number => Console.printLine(number)) | |
| } yield () | |
| logic.unsafeRun | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment