Skip to content

add \/ alias for either function #51

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

Merged
merged 6 commits into from
Oct 15, 2020
Merged

Conversation

srghma
Copy link
Contributor

@srghma srghma commented May 8, 2020

just like this is done for Tuple constructor in Data.Tuple.Nested

https://github.com/purescript/purescript-tuples/blob/v5.1.0/src/Data/Tuple/Nested.purs#L31-L31

@hdgarrood
Copy link
Contributor

At first I was like "maybe let's not add more operators" but this is actually super neat, since it lets you match on nested eithers rather nicely:

f :: (Int \/ String \/ Boolean) -> String
f = show \/ identity \/ if _ then "yes" else "no"

I would support adding this as long as it has some documentation. 👍

@srghma
Copy link
Contributor Author

srghma commented May 21, 2020

@hdgarrood tnx, what documentation would you propose? We can add the example you just posted or example with $

@hdgarrood
Copy link
Contributor

What do you mean by the example with $? The one I posted works for me, although it would be good to add examples of calling it with values from each “branch” of the nested Either to better indicate what it does in case it’s not immediately clear to the reader.

@srghma
Copy link
Contributor Author

srghma commented May 21, 2020

I've meant something like

calculationResult :: IO Int
calculationResult = throwError /\ pure $ Left "Error during calculation"

but your example is better

@srghma
Copy link
Contributor Author

srghma commented May 21, 2020

@hdgarrood could you add the documentation note yourself? I'm afraid I will make it wrong

@srghma
Copy link
Contributor Author

srghma commented Jun 3, 2020

@hdgarrood I have added comment, dont know why test fails

@hdgarrood
Copy link
Contributor

I think we're running into purescript-contrib/pulp#392. I've just published pulp v15.0.0 with a fix so hopefully updating will be enough here.

@hdgarrood
Copy link
Contributor

Sorry for the delay. How about this for the comments:

The `\/` operator alias for the `either` function allows easy matching on nested Eithers. For example, consider the function

    f :: (Int \/ String \/ Boolean) -> String
    f (Left x) = show x
    f (Right (Left y)) = y
    f (Right (Right z)) = if z then "Yes" else "No"

The `\/` operator alias allows us to rewrite this function as

    f :: (Int \/ String \/ Boolean) -> String
    f = show \/ identity \/ if _ then "Yes" else "No"

srghma added 2 commits June 4, 2020 11:23
…app/package.json creack/ncu -u --upgradeAll --packageFile /app/package.json"
@srghma
Copy link
Contributor Author

srghma commented Jun 4, 2020

@hdgarrood done

@hdgarrood
Copy link
Contributor

Thanks!

@srghma
Copy link
Contributor Author

srghma commented Jul 10, 2020

@hdgarrood or @hdgarrood or @natefaubion could someone merge it

it's not being merged without reason for so long

@hdgarrood
Copy link
Contributor

hdgarrood commented Jul 10, 2020

Sorry, but you don't get to set the timescales on these things. Our policy is that changes to the core libraries need to be reviewed by 2 people, and our attention is more directed towards the upcoming v0.14.0 release at the moment.

@srghma
Copy link
Contributor Author

srghma commented Jul 10, 2020

ok, at least now I know the reason

@JordanMartinez
Copy link
Contributor

@srghma Could you fix the merge conflicts? I think we can merge soon after that.

@srghma
Copy link
Contributor Author

srghma commented Oct 15, 2020

@hdgarrood done

@hdgarrood hdgarrood merged commit 36ba0fa into purescript:master Oct 15, 2020
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

Successfully merging this pull request may close these issues.

3 participants