New library: kill-bool
A while ago, I was working on some cache-based code, I had a primitive function:
It was intended to be used as follows:
ssoSignin p = do
userInfo <- fetchSsoInfo p
(wasCached, user) <- fetchCached userInfo.id
let sayWelcomeIfNew =
if wasCached
then return Nothing
else Just <$> mkWelcome user
(,) user <$> sayWelcomeIfNew
Actually, this design is kind of flawed, Bool
being not explicit enough to know from the type signature whether True
mean it was cached or it is new.
Which quickly led to this mistake:
something p = do
-- ...
(wasCached, y) <- fetchCached x
unless wasCached $
doSomethingAtCreation y
A solution would be to create a dedicated type, but instead, I made a simple library, kill-bool, to make sense of Bool
s without the burden of defining one-time types..
(TBool
for Typed-Bool
)
Which helps us to write less ambiguous code:
ssoSignin p = do
userInfo <- fetchSsoInfo p
(wasCached, user) <- fetchCached userInfo.id
let sayWelcomeIfNew =
if is (Proxy @"cached") wasCached
then return Nothing
else Just <$> mkWelcome user
(,) user <$> sayWelcomeIfNew
Note: it was named after Quentin Tarantino's Kill Bill movies