{-# LANGUAGE CPP #-}
module Haxl.Core.Util
( compose
, textShow
, tryReadMVar
) where
#if __GLASGOW_HASKELL__ >= 708
import Control.Concurrent (tryReadMVar)
#else
import Control.Concurrent
#endif
import Data.Text (Text)
import qualified Data.Text as Text
compose :: [a -> a] -> a -> a
compose = foldr (.) id
#if __GLASGOW_HASKELL__ < 708
tryReadMVar :: MVar a -> IO (Maybe a)
tryReadMVar m = do
mb <- tryTakeMVar m
case mb of
Nothing -> return Nothing
Just a -> putMVar m a >> return (Just a)
#endif
textShow :: (Show a) => a -> Text
textShow = Text.pack . show