Last active
April 11, 2023 16:47
-
-
Save dacr/1edeb107fb650d1558095c4984e490c2 to your computer and use it in GitHub Desktop.
zio-streams ZStream collectZIO stucked forever #7301 ? / published by https://github.com/dacr/code-examples-manager #84637c86-ace7-4483-907c-c59cffd2d616/261145b4ef278ff1502aa7c835db5983537c330b
This file contains 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 ? | |
// 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 : 84637c86-ace7-4483-907c-c59cffd2d616 | |
// 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.2.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")) | |
.collectZIO { case file @ mask(timestamp, group) => parseTimestamp(timestamp).map(ts => ts -> file) } // https://github.com/zio/zio/issues/7301 | |
.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