sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

Can we rework encase to allow any type to be thrown? #646

Closed Avaq closed 4 years ago

Avaq commented 4 years ago

Something like this:

- encase :: (a -> b) -> a -> Either Error b
+ encase :: Throwing e (a -> b) -> a -> Either e b

Because I'm getting bitten by the fact that I expect a function to be safe after using encase, only to find out that it now throws a TypeError because the function I've encased throws a String.

davidchambers commented 4 years ago

I like this change. I don't know about the notation, though. Throwing e (a -> b) should probably be Throwing e a b, because a -> b is sugar for Fn a b and Throwing e (Fn a b) doesn't make sense to me. Another option is just to replace Error with e and explain in the description how the type of e is determined. What do you think?

Avaq commented 4 years ago

Throwing e (a -> b) should probably be Throwing e a b

You're totally right. I will also update Fluture's encase docs accordingly!