Last active
May 25, 2024 08:39
-
-
Save dacr/26132a03a758fcc56a3833895887c251 to your computer and use it in GitHub Desktop.
zio-streams ZStream collectZIO stucked forever #7301 ? the ok case replacing collectZIO with mapZIO / published by https://github.com/dacr/code-examples-manager #3d78d1a8-0114-473e-abe4-b923b5af6341/b1b329c1ad243f7f0c523a263cf4064f6fb41972
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-streams ZStream collectZIO stucked forever #7301 ? the ok case replacing collectZIO with mapZIO | |
// keywords : scala, ziostream, issue | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 3d78d1a8-0114-473e-abe4-b923b5af6341 | |
// created-on : 2022-09-03T09:32:10+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// attached-files | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "dev.zio::zio-streams:2.0.10" | |
// --------------------- | |
// https://github.com/zio/zio/issues/7301 | |
import zio.* | |
import zio.stream.* | |
import scala.util.matching.Regex | |
import java.time.LocalDateTime | |
import java.time.format.DateTimeFormatter | |
object Photos extends ZIOAppDefault { | |
def parseTimestamp(timestamp: String): ZIO[Any, Throwable, LocalDateTime] = ZIO.succeed(LocalDateTime.now()) | |
def run = for { | |
_ <- ZIO.log(s"scanning...") | |
mask <- ZIO.attempt(""".*/(\d{8}-\d{6})-\d{2}-(.*)-evt.jpg""".r) | |
entries <- | |
ZStream | |
.fromIterable(List("./20220902-162930-00-raspcam1-evt.jpg", "./20220901-195134-00-raspcam1-evt.jpg", "./20220901-204013-00-raspcam1-evt.jpg")) | |
.filterNot(_.contains("Trash")) | |
.mapZIO { | |
case file@mask(timestamp, group) => parseTimestamp(timestamp).map(ts => Some(ts -> file)) | |
case _ => ZIO.succeed(None) | |
} | |
.collect { case Some(photo) => photo } | |
.tap(f => ZIO.log(s"found $f")) | |
.runCollect | |
_ <- ZIO.log(s"found ${entries.size} entries") | |
} yield () | |
} | |
Photos.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment