Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type alias for Checks, converting from Some to error #4841

Closed
tyrcho opened this issue Mar 25, 2021 · 7 comments
Closed

type alias for Checks, converting from Some to error #4841

tyrcho opened this issue Mar 25, 2021 · 7 comments

Comments

@tyrcho
Copy link
Contributor

tyrcho commented Mar 25, 2021

I have identified a recurring pattern in our project using ZIO.

We want to fail when some function returns Some(x) and succeed when it returns None.

I'm thinking of defining a method like this one:

def noneOrFail[E,O](o:Option[O], f:O=>E):IO[E,Unit]=
    ZIO.fromEither(o.toLeft(())).mapError(f)
    // similar implementation
    //ZIO.getOrFailUnit(o).flip.mapError(f) 

And maybe a new type Alias

type Check[E] = IO[E, Unit]

Is there a more standard way to do this with ZIO?
Otherwise, is this an extension you'd be interested to add ?

@adamgfraser
Copy link
Contributor

I think variants of getOrFail that expect the None case would be fine. Check type alias seems a little specialized to me.

@tyrcho
Copy link
Contributor Author

tyrcho commented Mar 26, 2021

thanks for the reply. I agree for the type alias.

about noneOrFail, would you like me to submit a PR ? only the ZIO trait needs a change, right ?

@adamgfraser
Copy link
Contributor

I think it would be a constructor so it would go on the ZIO companion object, right? When we add methods to the companion object we also add aliases for them to the companion objects for the various ZIO type aliases like Task with the appropriate constraints.

tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
@tyrcho
Copy link
Contributor Author

tyrcho commented Mar 29, 2021

Here is the PR : #4851

I struggled with the unit tests.

tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 29, 2021
@tyrcho
Copy link
Contributor Author

tyrcho commented Mar 29, 2021

cleaned the format + signed the CLA

tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 31, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 31, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Mar 31, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Apr 1, 2021
tyrcho pushed a commit to tyrcho/zio that referenced this issue Apr 7, 2021
adamgfraser pushed a commit that referenced this issue Apr 7, 2021
* Implement noneOrFail #4841

* currify noneOrFailWith + aliases in RIO, Task
@tyrcho tyrcho closed this as completed Apr 7, 2021
@tyrcho
Copy link
Contributor Author

tyrcho commented Apr 8, 2021

actually, I'll let this open until the feature is available in the next release

@tyrcho tyrcho reopened this Apr 8, 2021
@adamgfraser
Copy link
Contributor

I think if we have implemented the feature we should close the issue even if it is not in the latest release yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants