{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoImplicitPrelude #-} module Data.Morpheus.Subscriptions.Event ( Event (..), runEvents, ) where import Data.Morpheus.App.Internal.Resolving ( EventHandler (..), ) import Relude data Event ch con = Event { forall ch con. Event ch con -> [ch] channels :: [ch], forall ch con. Event ch con -> con content :: con } instance EventHandler (Event ch con) where type Channel (Event ch con) = ch getChannels :: Event ch con -> [Channel (Event ch con)] getChannels = forall ch con. Event ch con -> [ch] channels runEvents :: (Foldable t, Applicative f) => t (event -> f b) -> event -> f () runEvents :: forall (t :: * -> *) (f :: * -> *) event b. (Foldable t, Applicative f) => t (event -> f b) -> event -> f () runEvents t (event -> f b) fs event e = forall (t :: * -> *) (f :: * -> *) a b. (Foldable t, Applicative f) => (a -> f b) -> t a -> f () traverse_ (event e forall a b. a -> (a -> b) -> b &) t (event -> f b) fs