module H3.Internal.Utils
  ( toEither
  ) where

import H3.Internal.H3Api 
  ( H3Error
  , H3ErrorCodes )


toEither :: (H3Error, a) -> Either H3ErrorCodes a
toEither :: forall a. (H3Error, a) -> Either H3ErrorCodes a
toEither (H3Error
h3error, a
res) =
  if H3Error
h3error H3Error -> H3Error -> Bool
forall a. Eq a => a -> a -> Bool
/= H3Error
0
  then H3ErrorCodes -> Either H3ErrorCodes a
forall a b. a -> Either a b
Left ((Int -> H3ErrorCodes
forall a. Enum a => Int -> a
toEnum (Int -> H3ErrorCodes)
-> (H3Error -> Int) -> H3Error -> H3ErrorCodes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Error -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) H3Error
h3error)
  else a -> Either H3ErrorCodes a
forall a b. b -> Either a b
Right a
res