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

Add withFilter and filter to XorT #1294

Closed
mkotsbak opened this issue Aug 17, 2016 · 2 comments
Closed

Add withFilter and filter to XorT #1294

mkotsbak opened this issue Aug 17, 2016 · 2 comments

Comments

@mkotsbak
Copy link
Contributor

This will allow to use if statements in for-comprehensions. See similar issue for OptionT: #981

@ceedubs
Copy link
Contributor

ceedubs commented Aug 18, 2016

I think that OptionT is a bit different than XorT in this context. If you filter out an item from an Option then you can naturally return None. What do you return in the case of Xor/XorT for an empty value? Xor used to require a Monoid instance for the left type and use the empty value from that Monoid, but it was removed in #276 as it was pretty ad-hoc and arbitrary. For example what should the following return?

val x: String Xor Int = Right(3)
val y = x.filter(_ % 2 == 0)

With a Monoid empty it would return Left(""). To me this seems pretty arbitrary and probably unhelpful. I think it's better to do something like:

val x: String Xor Int = Right(3)
val y = x.ensure("oops it was odd!")(_ % 2 == 0)

Note that I'm using Xor in these examples but I think it all applies equally well to XorT.

@mkotsbak
Copy link
Contributor Author

Agree, this is not solvable.

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