-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Adds toEither :: a -> b? -> Either a b
#249
Conversation
Very nice! I'll make several comments about minor issues, but they should all be easy to address. :) |
|
||
it('returns Left of the first argument when second argument is `null`', function() { | ||
eq(S.toEither('a', null), S.Left('a')); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's include an assertion for S.toEither('a', undefined)
.
@davidchambers Do you prefer that I add commits separately during the review process and squash at the end, or just push up the amended commit as I fix? |
//. | ||
//. Takes a failure value, 'x', and a possibly null or undefined value, 'y'. | ||
//. Returns a Right of 'y' if it is defined and not null, otherwise returns | ||
//. a Left of 'x'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find mention of "'x'" and "'y'" a bit confusing. I think we could get away with referring to "the first argument" and "the second argument".
How about this?
Converts an arbitrary value to an Either: a Left if the value is null
or undefined
; a Right otherwise. The first argument specifies the value of the Left in the "failure" case.
I'd like to improve the descriptions of many of the library's functions. In many cases the description is just an English translation of the type signature. In this case, for example, a direct translation would be:
Returns a Left of its first argument if its second argument is null
or undefined
; a Right of its second argument otherwise.
I like the mention of a "failure value" in your description. I'd like to avoid mention of "'x'" and "'y'" though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! I'd modelled this after encaseEither
, but I guess naming arguments is more important when some are functions
I'm happy either way. Use whichever process works better for you. |
@davidchambers I think that's everything addressed |
Thanks for the quick updates. I have three more requests:
|
⚡ |
A function for converting a possibly null-y value to an Either
@@ -1265,7 +1265,7 @@ | |||
|
|||
//# toMaybe :: a? -> Maybe a | |||
//. | |||
//. Takes a value and returns Nothing if the value is null or undefined; | |||
//. Takes a value and returns Nothing if the value is `null` or `undefined`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Very nice patch, @rjmk. Thank you for tolerating my nitpicking. :) 🌳 |
|
A function for converting a possibly null-y value to an Either
Closes #83