{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE BlockArguments #-}

-- | Chan Transport Instance.

module Control.Churro.Transport.Unagi where
    
import Control.Churro.Types
import Control.Churro.Prelude

import Control.Concurrent.Chan.Unagi
import Data.Void

data Unagi a

instance Transport Unagi where
    data In  Unagi a = ChanIn  (InChan  a)
    data Out Unagi a = ChanOut (OutChan a)
    yank :: forall a. Out Unagi a -> IO a
yank (ChanOut OutChan a
c) = forall a. OutChan a -> IO a
readChan  OutChan a
c
    yeet :: forall a. In Unagi a -> a -> IO ()
yeet (ChanIn  InChan a
c) = forall a. InChan a -> a -> IO ()
writeChan InChan a
c
    flex :: forall a. IO (In Unagi a, Out Unagi a)
flex = do 
        (InChan a
i, OutChan a
o) <- forall a. IO (InChan a, OutChan a)
newChan
        forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. InChan a -> In Unagi a
ChanIn InChan a
i, forall a. OutChan a -> Out Unagi a
ChanOut OutChan a
o)

type ChurroUnagi a = Churro a Unagi

-- | Convenience function for running a Churro with an Unagi Transport.
-- 
runWaitUnagi :: ChurroUnagi a Void Void -> IO a
runWaitUnagi :: forall a. ChurroUnagi a Void Void -> IO a
runWaitUnagi = forall (t :: * -> *) a. Transport t => Churro a t Void Void -> IO a
runWait

-- | Convenience function for running a Churro into a List with an Unagi Transport.
-- 
runWaitListUnagi :: ChurroUnagi () Void o -> IO [o]
runWaitListUnagi :: forall o. ChurroUnagi () Void o -> IO [o]
runWaitListUnagi = forall (t :: * -> *) a b.
(Transport t, Monoid a) =>
Churro a t Void b -> IO [b]
runWaitList