<commit_before>-- @+leo-ver=5-thin
-- @+node:gcross.20111026172030.1274: * @file Control/Monad/Trans/Visitor/Reactive/Worker.hs
-- @@language haskell

-- @+<< Language extensions >>
-- @+node:gcross.20111026172030.1275: ** << Language extensions >>
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UnicodeSyntax #-}
-- @-<< Language extensions >>

module Control.Monad.Trans.Visitor.Reactive.Worker where

-- @+<< Import needed modules >>
-- @+node:gcross.20111026172030.1276: ** << Import needed modules >>
import Control.Arrow ((&&&),second)
import Control.Exception (Exception(..),SomeException)
import Control.Concurrent (killThread)
import Control.Monad ((>=>),unless)
import Control.Monad.IO.Class
import Control.Monad.Tools (whenM,unlessM)

import Data.Derive.Monoid
import Data.DeriveTH
import Data.Either.Unwrap (fromLeft,fromRight,isLeft,isRight)
import Data.IORef (IORef,atomicModifyIORef,newIORef,readIORef,writeIORef)
import qualified Data.IVar as IVar
import Data.Maybe (fromJust,isJust)
import Data.Monoid (Monoid(..))
import Data.Monoid.Unicode ((⊕))
import Data.Sequence ((|>))

import Reactive.Banana

import Control.Monad.Trans.Visitor
import Control.Monad.Trans.Visitor.Checkpoint
import Control.Monad.Trans.Visitor.Worker
import Control.Monad.Trans.Visitor.Workload
-- @-<< Import needed modules >>

-- @+others
-- @+node:gcross.20111026220221.1284: ** Exceptions
-- @+node:gcross.20111026220221.1285: *3* RedundantWorkloadReceived
data RedundantWorkloadReceived = RedundantWorkloadReceived deriving (Eq,Show,Typeable)

instance Exception RedundantWorkloadReceived
-- @+node:gcross.20111026172030.1280: ** Types
-- @+node:gcross.20111219115425.1411: *3* WorkerIncomingEvents
data WorkerIncomingEvents = WorkerIncomingEvents
	{	workerIncomingStatusUpdateRequestedEvent :: Event ()
	,	workerIncomingWorkloadStealRequestedEvent :: Event ()
	,	workerIncomingShutdownEvent :: Event ()
	,	workerIncomingWorkloadReceivedEvent :: Event VisitorWorkload
	}

$( derive makeMonoid ''WorkerIncomingEvents )
-- @+node:gcross.20111219115425.1412: *3* WorkerOutgoingEvents
data WorkerOutgoingEvents α = WorkerOutgoingEvents
	{	workerOutgoingMaybeStatusUpdatedEvent :: Event (Maybe (VisitorWorkerStatusUpdate α))
	,	workerOutgoingMaybeWorkloadSubmittedEvent :: Event (Maybe (VisitorWorkerStatusUpdate α,VisitorWorkload))
	,	workerOutgoingFinishedEvent :: Event (VisitorWorkerFinalUpdate α)
	,	workerOutgoingFailureEvent :: Event SomeException
	}

$( derive makeMonoid ''WorkerOutgoingEvents )
-- @+node:gcross.20111026213013.1280: *3* VisitorWorkerReactiveRequest
data VisitorWorkerReactiveRequest =
    StatusUpdateReactiveRequest
  | WorkloadStealReactiveRequest
-- @+node:gcross.20111026172030.1281: ** Functions
-- @+node:gcross.20111219132352.1428: *3* (<$?>)
infixl 4 <$?>

(<$?>) :: (a → Maybe b) → Event a → Event b
(<$?>) f = filterJust . fmap f
-- @+node:gcross.20111219132352.1427: *3* (<$↔>)
infixl 4 <$↔>

(<$↔>) :: (a → Either b c) → Event a → (Event b,Event c)
f <$↔> x = split (f <$> x)
-- @+node:gcross.20111026220221.1283: *3* (<@↔>)
infixl 4 <@↔>

(<@↔>) :: Apply f Event ⇒ f (a → Either b c) → Event a → (Event b,Event c)
f <@↔> x = split (f <@> x)
-- @+node:gcross.20111117140347.1433: *3* createVisitorIOWorkerNetwork
createVisitorIOWorkerReactiveNetwork ::
    WorkerIncomingEvents →
    VisitorIO α →
    NetworkDescription (WorkerOutgoingEvents α)
createVisitorIOWorkerReactiveNetwork = createVisitorTWorkerReactiveNetwork id
-- @+node:gcross.20111026220221.1457: *3* createVisitorTWorkerNetwork
createVisitorTWorkerReactiveNetwork ::<commit_msg>Cosmetic fix: Replaced tabs with spaces.<commit_after>-- @+leo-ver=5-thin
-- @+node:gcross.20111026172030.1274: * @file Control/Monad/Trans/Visitor/Reactive/Worker.hs
-- @@language haskell

-- @+<< Language extensions >>
-- @+node:gcross.20111026172030.1275: ** << Language extensions >>
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UnicodeSyntax #-}
-- @-<< Language extensions >>

module Control.Monad.Trans.Visitor.Reactive.Worker where

-- @+<< Import needed modules >>
-- @+node:gcross.20111026172030.1276: ** << Import needed modules >>
import Control.Arrow ((&&&),second)
import Control.Exception (Exception(..),SomeException)
import Control.Concurrent (killThread)
import Control.Monad ((>=>),unless)
import Control.Monad.IO.Class
import Control.Monad.Tools (whenM,unlessM)

import Data.Derive.Monoid
import Data.DeriveTH
import Data.Either.Unwrap (fromLeft,fromRight,isLeft,isRight)
import Data.IORef (IORef,atomicModifyIORef,newIORef,readIORef,writeIORef)
import qualified Data.IVar as IVar
import Data.Maybe (fromJust,isJust)
import Data.Monoid (Monoid(..))
import Data.Monoid.Unicode ((⊕))
import Data.Sequence ((|>))

import Reactive.Banana

import Control.Monad.Trans.Visitor
import Control.Monad.Trans.Visitor.Checkpoint
import Control.Monad.Trans.Visitor.Worker
import Control.Monad.Trans.Visitor.Workload
-- @-<< Import needed modules >>

-- @+others
-- @+node:gcross.20111026220221.1284: ** Exceptions
-- @+node:gcross.20111026220221.1285: *3* RedundantWorkloadReceived
data RedundantWorkloadReceived = RedundantWorkloadReceived deriving (Eq,Show,Typeable)

instance Exception RedundantWorkloadReceived
-- @+node:gcross.20111026172030.1280: ** Types
-- @+node:gcross.20111219115425.1411: *3* WorkerIncomingEvents
data WorkerIncomingEvents = WorkerIncomingEvents
    {   workerIncomingStatusUpdateRequestedEvent :: Event ()
    ,   workerIncomingWorkloadStealRequestedEvent :: Event ()
    ,   workerIncomingShutdownEvent :: Event ()
    ,   workerIncomingWorkloadReceivedEvent :: Event VisitorWorkload
    }

$( derive makeMonoid ''WorkerIncomingEvents )
-- @+node:gcross.20111219115425.1412: *3* WorkerOutgoingEvents
data WorkerOutgoingEvents α = WorkerOutgoingEvents
    {   workerOutgoingMaybeStatusUpdatedEvent :: Event (Maybe (VisitorWorkerStatusUpdate α))
    ,   workerOutgoingMaybeWorkloadSubmittedEvent :: Event (Maybe (VisitorWorkerStatusUpdate α,VisitorWorkload))
    ,   workerOutgoingFinishedEvent :: Event (VisitorWorkerFinalUpdate α)
    ,   workerOutgoingFailureEvent :: Event SomeException
    }

$( derive makeMonoid ''WorkerOutgoingEvents )
-- @+node:gcross.20111026213013.1280: *3* VisitorWorkerReactiveRequest
data VisitorWorkerReactiveRequest =
    StatusUpdateReactiveRequest
  | WorkloadStealReactiveRequest
-- @+node:gcross.20111026172030.1281: ** Functions
-- @+node:gcross.20111219132352.1428: *3* (<$?>)
infixl 4 <$?>

(<$?>) :: (a → Maybe b) → Event a → Event b
(<$?>) f = filterJust . fmap f
-- @+node:gcross.20111219132352.1427: *3* (<$↔>)
infixl 4 <$↔>

(<$↔>) :: (a → Either b c) → Event a → (Event b,Event c)
f <$↔> x = split (f <$> x)
-- @+node:gcross.20111026220221.1283: *3* (<@↔>)
infixl 4 <@↔>

(<@↔>) :: Apply f Event ⇒ f (a → Either b c) → Event a → (Event b,Event c)
f <@↔> x = split (f <@> x)
-- @+node:gcross.20111117140347.1433: *3* createVisitorIOWorkerNetwork
createVisitorIOWorkerReactiveNetwork ::
    WorkerIncomingEvents →
    VisitorIO α →
    NetworkDescription (WorkerOutgoingEvents α)
createVisitorIOWorkerReactiveNetwork = createVisitorTWorkerReactiveNetwork id
-- @+node:gcross.20111026220221.1457: *3* createVisitorTWorkerNetwork
createVisitorTWorkerReactiveNetwork ::
{'fraction_non_alphanumeric': 0.14194556582888396, 'fraction_numerical': 0.0739679645787212, 'mean_word_length': 5.626402070750647, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '925455', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2661, 'n_words': 525}