{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}{-# OPTIONS_HADDOCK prune #-}moduleDatabase.CouchDB.ViewServer.Reduce(-- * Map FunctionsReduceSignature,ViewReduce-- * JSON Parsing,moduleDatabase.CouchDB.ViewServer.Parse-- * ViewReduce Monads,logMsg,ReduceOutput,ReduceFunc,toReduceFunc,reduceFuncInterpreter,execReduceFunc)whereimportData.MaybeimportData.TypeableimportData.Aeson(toJSON,ToJSON)importData.Aeson.Types(Value(..),Object,Parser,parseMaybe)importControl.ApplicativeimportControl.Monad(Monad,MonadPlus)importControl.Monad.Trans.Class(lift)importControl.Monad.Trans.Writer(WriterT,tell,runWriterT)importqualifiedLanguage.Haskell.InterpreterasHimportDatabase.CouchDB.ViewServer.InternalimportDatabase.CouchDB.ViewServer.ParsetypeReduceOutput=(Value,[LogMessage]){- | The monad within which a reduce computation takes place. This is a
transformation of the 'Data.Aeson.Types.Parser' monad, which is accessible
through the 'MonadParser' typeclass.
-}newtypeViewReducea=ViewReduce{runViewReduce::WriterT[LogMessage]Parsera}deriving(Monad,Functor,MonadPlus,Applicative,Alternative)instanceMonadParserViewReducewhereliftParser=ViewReduce.lift{- | The type of your reduce functions as they are stored in CouchDB. The trivial
example:
> \keys values rereduce -> return Null
-}typeReduceSignaturea=[Value]->[Value]->Bool->ViewReduceanewtypeReduceFunc=ReduceFunc{runReduceFunc::ReduceSignatureValue}deriving(Typeable)toReduceFunc::ToJSONa=>ReduceSignaturea->ReduceFunctoReduceFuncf=ReduceFunc$\kvr->toJSON<$>fkvrreduceFuncInterpreter::[H.OptionValH.Interpreter]->[(H.ModuleName,MaybeString)]->String->H.InterpreterReduceFuncreduceFuncInterpreteroptsmodssource=doH.setoptsH.setImportsQ$mods++[("Database.CouchDB.ViewServer.Reduce",Nothing)]H.interpret("toReduceFunc "++H.parenssource)(H.as::ReduceFunc)execReduceFunc::ReduceFunc->[Value]->[Value]->Bool->ReduceOutputexecReduceFuncreduceFunckeysvaluesrereduce=fromMaybe(Null,[])$parseMayberunWriterT(runViewReduce$runReduceFuncreduceFunckeysvaluesrereduce){- | Send a log message to the CouchDB server. Note that log messages are only
sent if the computation succeeds. If you want to log a message in the event
of a failure, look at 'Control.Applicative.Alternative'.
-}logMsg::String->ViewReduce()logMsgmsg=ViewReduce$tell[LogMessagemsg]