-- |
-- Module     : Simulation.Aivika.GPSS.Block.Depart
-- Copyright  : Copyright (c) 2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.2
--
-- This module defines the GPSS block DEPART.
--
module Simulation.Aivika.GPSS.Block.Depart
       (departBlock) where

import Simulation.Aivika
import Simulation.Aivika.GPSS.Transact
import Simulation.Aivika.GPSS.Block
import qualified Simulation.Aivika.GPSS.Queue as Q

-- | This is the GPSS construct
--
-- @DEPART A,B@
departBlock :: Q.Queue
               -- ^ the queue
               -> Int
               -- ^ the content decrement
               -> Block (Transact a) (Transact a)
departBlock :: Queue -> Int -> Block (Transact a) (Transact a)
departBlock Queue
q Int
decrement =
  Block :: forall a b. (a -> Process b) -> Block a b
Block { blockProcess :: Transact a -> Process (Transact a)
blockProcess = \Transact a
a -> (Event () -> Process ()
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event () -> Process ()) -> Event () -> Process ()
forall a b. (a -> b) -> a -> b
$ Queue -> Transact a -> Int -> Event ()
forall a. Queue -> Transact a -> Int -> Event ()
Q.dequeue Queue
q Transact a
a Int
decrement) Process () -> Process (Transact a) -> Process (Transact a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Transact a -> Process (Transact a)
forall (m :: * -> *) a. Monad m => a -> m a
return Transact a
a }