module Overloaded.If (
ToBool (..),
ifte,
) where
import Data.Maybe (isJust)
import Data.Either (isRight)
class ToBool b where
toBool :: b -> Bool
instance ToBool Bool where
toBool :: Bool -> Bool
toBool = Bool -> Bool
forall a. a -> a
id
instance ToBool (Maybe a) where
toBool :: Maybe a -> Bool
toBool = Maybe a -> Bool
forall a. Maybe a -> Bool
isJust
instance ToBool (Either b a) where
toBool :: Either b a -> Bool
toBool = Either b a -> Bool
forall b a. Either b a -> Bool
isRight
ifte :: ToBool b => b -> a -> a -> a
ifte :: b -> a -> a -> a
ifte b
b a
t a
e = if b -> Bool
forall b. ToBool b => b -> Bool
toBool b
b then a
t else a
e