Closed mrcjkb closed 2 years ago
Thanks for the patch. I wonder how useful these functions are? Wouldn't you usually want to replace the left by wrapping the underlying error, so that the original error message is still available? I note that replaceRight
is already available as $>
- which I'm generally a fan of more specialised functions, things like $>
are pretty universal, so a little less concerning.
I wonder how useful these functions are? Wouldn't you usually want to replace the left by wrapping the underlying error, so that the original error message is still available?
In most cases, I would agree. In some cases, I am replacing an error that has a no-arg constructor with my own error that has a no-arg constructor. There is a direct mapping between SpecialError
and a specific error constructor, (so no information is lost by not wrapping the error) and the sole purpose is encapsulation of the libraries I am using.
I could use SpecialError a
with a generic argument to encapsulate the library's error from my API, but in this case it would just lead to more code and a less simple API without any benefits.
Another use case would be if I want to log the original Left
and then replace it with a simpler error message that is later printed to stderr
in a command line app.
I personally have not had any use for replaceRight
. I just added it because the module has a Right
function for each Left
function and vice versa.
Thanks for the contribution. Alas, I think these functions probably don't being in extra just yet, for 4 interlinked reasons:
mapLeft . const
isn't that much longer.replace
is used with string/list replacement, not the replacing on inner components of structures.
[x] By raising this pull request you confirm you are licensing your contribution under all licenses that apply to this project (see LICENSE) and that you have no patents covering your contribution.
[x] If you care, my PR preferences are at https://github.com/ndmitchell/neil#contributions, but they're all guidelines, and I'm not too fussy - you don't have to read them.
I find the
replaceLeft
function useful for "translating" error handling from a library's domain to my own domain (to encapsulate the library's domain).Example (pseudo code):
GitHashException
: