You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A recent version of Data.Either moved fromRight and fromLeft to no longer be be partial but to provide a default. Perhaps these should be a Data.Either.Partial.from* version as can be seen with: purescript/purescript-strings#128
The better option now is to use either (unsafeCrashWith "...") identity, where ... is some kind of explanation of what it is or why it went wrong.
We could perhaps add them back under an Either.Unsafe module, but I think it would be better if they included a string still, so there's some clue to what went wrong in the inconceivable case that they do actually fail. 😉
I would prefer not to re-add them; I don’t think they’re useful often enough to justify a spot here, especially since writing fromRight (crashWith "...") is only one more function application.
Oh, haha, oops. So I guess we'd need to do something like either (\_ -> unsafeCrashWith "...") identity. The total version of fromRight is not suitable for this at all then, I guess you'd have to do something like (_ $ unit) <<< fromRight (\_ -> unsafeCrashWith "..") <<< map const.
Maybe we want lazy versions of the form fromRight' :: forall a b. (Unit -> b) -> Either a b -> b?
Ah yeah, I used either exactly so it could be (\_ -> ....) in that branch, rather than suggesting fromRight (crashWith ..., but then didn't write it out properly 😉. But yeah, adding the lazy fromLeft / fromRight would also work and perhaps be worthwhile.
Assuming this is a common thing (which wouldn't surprise me given that it's in the library already), what should the message say? "Invalid RegExp: input_string_here"?
Should we consider an unsafeFromRight :: Either String a -> a function as an alias for either unsafeCrashWith identity?
Otherwise is there anything left to do now that we have fromLeft' :: forall a b. (Unit -> a) -> Either a b -> a and fromRight' :: forall a b. (Unit -> b) -> Either a b -> b or can we close this issue?
I think I would prefer to close the issue; the fromLeft' and fromRight' functions definitely ought to help fill this gap, and more API surface is a liability. I think arguably we shouldn't be encouraging use of unsafe functions by making them too comfortable to reach; that's a principle we've followed in the core libraries fairly consistently.
Activity
[-]Consider Unsafe for Partial[/-][+]Consider Unsafe or Partial for `from*`[/+]garyb commentedon Oct 20, 2020
The better option now is to use
either (unsafeCrashWith "...") identity, where...is some kind of explanation of what it is or why it went wrong.We could perhaps add them back under an
Either.Unsafemodule, but I think it would be better if they included a string still, so there's some clue to what went wrong in the inconceivable case that they do actually fail. 😉hdgarrood commentedon Oct 20, 2020
I would prefer not to re-add them; I don’t think they’re useful often enough to justify a spot here, especially since writing
fromRight (crashWith "...")is only one more function application.toastal commentedon Oct 20, 2020
That's a smart option too! I wasn't sure the correct route would be. But I can update the
stringslib once the message is settled.natefaubion commentedon Oct 20, 2020
Let’s not forget which language we are programming in 😅 😜 This will totally type check and crash immediately.
hdgarrood commentedon Oct 20, 2020
Oh, haha, oops. So I guess we'd need to do something like
either (\_ -> unsafeCrashWith "...") identity. The total version offromRightis not suitable for this at all then, I guess you'd have to do something like(_ $ unit) <<< fromRight (\_ -> unsafeCrashWith "..") <<< map const.Maybe we want lazy versions of the form
fromRight' :: forall a b. (Unit -> b) -> Either a b -> b?garyb commentedon Oct 20, 2020
Ah yeah, I used
eitherexactly so it could be(\_ -> ....)in that branch, rather than suggestingfromRight (crashWith ..., but then didn't write it out properly 😉. But yeah, adding the lazyfromLeft/fromRightwould also work and perhaps be worthwhile.toastal commentedon Oct 20, 2020
Assuming this is a common thing (which wouldn't surprise me given that it's in the library already), what should the message say?
"Invalid RegExp: input_string_here"?hdgarrood commentedon Oct 20, 2020
We should probably reuse the error from the Left constructor, so actually I suppose
either unsafeCrashWith identityshould work.toastal commentedon Oct 20, 2020
Seems reasonable. I'll have a look after my shower.
JordanMartinez commentedon Dec 5, 2020
Since Maybe has a lazy version of
fromMaybe: fromMaybe', should this library have the same forfromLeftandfromRight, too?kl0tl commentedon Dec 18, 2020
Should we consider an
unsafeFromRight :: Either String a -> afunction as an alias foreither unsafeCrashWith identity?Otherwise is there anything left to do now that we have
fromLeft' :: forall a b. (Unit -> a) -> Either a b -> aandfromRight' :: forall a b. (Unit -> b) -> Either a b -> bor can we close this issue?hdgarrood commentedon Dec 18, 2020
I think I would prefer to close the issue; the
fromLeft'andfromRight'functions definitely ought to help fill this gap, and more API surface is a liability. I think arguably we shouldn't be encouraging use of unsafe functions by making them too comfortable to reach; that's a principle we've followed in the core libraries fairly consistently.JordanMartinez commentedon Dec 18, 2020
I'm in favor of closing this, too.