chatty 0.4.0.0 → 0.4.1.0
raw patch · 3 files changed
+64/−2 lines, 3 files
Files
- Text/Chatty/Channel/Broadcast.hs +44/−0
- Text/Chatty/Interactor/Templates.hs +18/−0
- chatty.cabal +2/−2
+ Text/Chatty/Channel/Broadcast.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}+{-+ This module is part of Chatty.+ Copyleft (c) 2014 Marvin Cohrs++ All wrongs reversed. Sharing is an act of love, not crime.+ Please share Antisplice with everyone you like.++ Chatty is free software: you can redistribute it and/or modify+ it under the terms of the GNU Affero General Public License as published by+ the Free Software Foundation, either version 3 of the License, or+ (at your option) any later version.++ Chatty is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU Affero General Public License for more details.++ You should have received a copy of the GNU Affero General Public License+ along with Chatty. If not, see <http://www.gnu.org/licenses/>.+-}++-- | Provides a printer class that may broadcast to all channels that fulfill a condition.+module Text.Chatty.Channel.Broadcast where++import Control.Arrow+import Control.Monad+import Control.Monad.IO.Class+import Control.Monad.Trans.Class+import Text.Chatty.Printer+import Text.Chatty.Channel.Printer++-- | Typeclass for all channel printers that may broadcast to all channels that fulfill a condition.+class ChannelPrinter c m => Broadcaster c m where+ -- | Run the function and print to all channels that fulfill the given condition.+ bbracket :: (c -> m Bool) -> m a -> m a+ bbracket f m = bstart f >> m >>= \a -> bfin f >> return a+ -- | From now on use the given condition to determine the channels to print to.+ bstart :: (c -> m Bool) -> m ()+ -- | Return to the previous condition. The argument is bogus (just for type inference).+ bfin :: (c -> m Bool) -> m ()+ -- | Print the string to all channels that fulfill the current condition.+ bprint :: (c -> m Bool) -> String -> m ()+ bprint f str = bbracket f $ mprint str
Text/Chatty/Interactor/Templates.hs view
@@ -31,6 +31,7 @@ import Text.Chatty.Expansion.Vars import Text.Chatty.Expansion.History import Text.Chatty.Channel.Printer+import Text.Chatty.Channel.Broadcast import System.Chatty.Spawn import Text.Chatty.Extended.Printer import Control.Monad@@ -85,9 +86,25 @@ where sx = strToType s cx = strToType c +{-- | Automatically derives a Broadcaster instance for you.+mkBroadcaster :: Name -> Name -> Q [Dec]+mkBroadcaster c s = [d|+ instance Broadcaster $cx m => Broadcaster $cx ($sx m) where+ bstart = lift . bstart+ bfin = lift . bfin+ bprint b = lift . bprint b+ |]+ where sx = strToType s+ cx = strToType c-}++-- | Automatically derives ChannelPrinter instances for 'Int', 'Bool' and 'Handle' channels. mkDefCP :: Name -> Q [Dec] mkDefCP s = mkInteractor s (mkChannelPrinter ''Int) (mkChannelPrinter ''Bool) (mkChannelPrinter ''Handle) +{-- | Automatically derives Broadcaster instances for 'Int', 'Bool' and 'Handle' channels+mkDefBC :: Name -> Q [Dec]+mkDefBC s = mkInteractor s (mkBroadcaster ''Int) (mkBroadcaster ''Bool) (mkBroadcaster ''Handle)-}+ -- | Automatically derives a MonadFinalizer instance for you. mkFinalizer :: Name -> Q [Dec] mkFinalizer s = [d|@@ -157,6 +174,7 @@ mkPrinter mkScanner mkFinalizer mkExpander mkSpawn mkRandom mkClock mkExpanderEnv mkHistoryEnv mkDefCP mkExtendedPrinter+-- mkDefBC -- | Automatically derives all chatty typeclasses that are sensible for an ArchiverT. mkArchiver :: Name -> Q [Dec]
chatty.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.4.0.0+version: 0.4.1.0 -- A short (one-line) description of the package. synopsis: Some monad transformers and typeclasses to simplify I/O on a transformer stack.@@ -48,7 +48,7 @@ library -- Modules exported by the library.- exposed-modules: Text.Chatty.Expansion, System.Chatty.Commands, System.Chatty.Spawn, Text.Chatty.Printer, Text.Chatty.Finalizer, Text.Chatty.Templates, Text.Chatty.Scanner, Text.Chatty.Interactor, System.Chatty.Spawn.Overlay, System.Chatty.Spawn.Builtins, Text.Chatty.Interactor.Templates, System.Chatty.Misc, Text.Chatty.Extended.Printer, Text.Chatty.Extended.HTML, Text.Chatty.Extended.ANSI, Text.Chatty.Expansion.Vars, Text.Chatty.Expansion.History, Text.Chatty.Channel.Printer+ exposed-modules: Text.Chatty.Expansion, System.Chatty.Commands, System.Chatty.Spawn, Text.Chatty.Printer, Text.Chatty.Finalizer, Text.Chatty.Templates, Text.Chatty.Scanner, Text.Chatty.Interactor, System.Chatty.Spawn.Overlay, System.Chatty.Spawn.Builtins, Text.Chatty.Interactor.Templates, System.Chatty.Misc, Text.Chatty.Extended.Printer, Text.Chatty.Extended.HTML, Text.Chatty.Extended.ANSI, Text.Chatty.Expansion.Vars, Text.Chatty.Expansion.History, Text.Chatty.Channel.Printer, Text.Chatty.Channel.Broadcast -- Modules included in this library but not exported. -- other-modules: