Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Stream.whenM for parity with ZIO.whenM #4387

@fanf

Description

@fanf

I have the use case where I want to take a decision based on an effect.
For ex: I want to walk a directory tree structure, and do things based on file existence.

I find a way to do it like that:

    ZStream.fromEffect(
      Task.effect(file.exists).catchAll(ex =>
        logger.error(ex.message *> ZIO.succeed(false)
      )
    ).flatMap(cond =>
      if(!cond) ZStream.empty
      else {
        ZStream.fromIterator(Task.effect(file.children)).... etc

But it feels combersome. I would love to have a combinator looking like:

    ZStream.ifFromEffect(effect (: ZIO[Any, Nothing, Boolean]))(ifTrue: ZStream)(ifFalse: ZStream)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions