-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | JsonLogic Evaluation -- -- JsonLogic is a library for evaluating JSON logic. It can be extended -- with additional operations @package jsonlogic @version 0.1.0.0 module JsonLogic.Json -- | Json is a collection of possible Json values. data Json JsonNull :: Json JsonBool :: Bool -> Json JsonNumber :: Double -> Json JsonString :: String -> Json JsonArray :: [Json] -> Json JsonObject :: JsonObject -> Json -- | A Json object is a map of string-Json pairs. type JsonObject = Map String Json -- | A rule can be any kind of Json value, but objects and arrays will be -- evaluated. type Rule = Json -- | Data can be any kind of Json value. type Data = Json -- | A pretty formatted show for the Json, with identation and depth Use -- putStr so the newline characters will be interpreted in console -- --
-- >>> putStr $ prettyShow JsonNull -- null ---- --
-- >>> putStr $ prettyShow $ JsonNumber 3.0 -- 3.0 ---- --
-- >>> prettyShow (JsonArray [JsonNumber 1, JsonNumber 2]) -- "[\n 1.0,\n 2.0\n]" ---- --
-- >>> putStr $ prettyShow (JsonArray [JsonNumber 1, JsonBool True]) -- [ -- 1.0, -- true -- ] --prettyShow :: Json -> String -- | Convert Json to string, used in string operations See -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString -- for more information. stringify :: Json -> String -- | Truthy test for Json See -- https://developer.mozilla.org/en-US/docs/Glossary/Truthy for -- more information. isTruthy :: Json -> Bool -- | The opposite of isTruthy isFalsy :: Json -> Bool -- | Convert Json to a numeric value, including NaN Same as the Parsefloat -- function in JS Parsefloat source: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat -- NaN source: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN parseFloat :: Json -> Double instance GHC.Classes.Eq JsonLogic.Json.Json instance GHC.Show.Show JsonLogic.Json.Json instance GHC.Read.Read JsonLogic.Json.Json module JsonLogic.Pure.Type -- | A result is an exception or a value. type Result r = Either Exception r -- | A subevaluator takes a rule and data and returns a result of Json. type SubEvaluator = Rule -> Data -> Result Json -- | A function takes a subevaluator, rule and data and returns a result. type Function r = SubEvaluator -> Rule -> Data -> Result r -- | An operation is a Json function with a name. type Operation = (String, Function Json) -- | Operations is a Map from the operation name to the operation function. type Operations = Map String (Function Json) -- | Throw an evaluation exception. throw :: String -> Result a -- | An evaluation exception thrown by the evaluator or operations. Is used -- in the result type. data Exception -- | Exception thrown when an unknown operation is applied. UnrecognizedOperation :: String -> Exception [operationName] :: Exception -> String -- | Exception thrown when a rule does not contain exactly one operation. InvalidRule :: [String] -> Exception [operationNames] :: Exception -> [String] -- | Exception thrown for any other error. EvalException :: String -> Exception [message] :: Exception -> String module JsonLogic.Pure.Operation -- | A map of all the default operations. defaultOperations :: Operations -- | Groups of operations on similar data. arrayOperations :: Operations -- | Array operations. map :: Operation -- | Array operations. reduce :: Operation -- | Array operations. filter :: Operation -- | Array operations. all :: Operation -- | Array operations. none :: Operation -- | Array operations. some :: Operation -- | Array operations. merge :: Operation -- | Array operations. in' :: Operation -- | Groups of operations on similar data. booleanOperations :: Operations -- | Boolean operations. if' :: Operation -- | Boolean operations. (==) :: Operation -- | Boolean operations. (===) :: Operation -- | Boolean operations. (!=) :: Operation -- | Boolean operations. (!==) :: Operation -- | Boolean operations. (!) :: Operation -- | Boolean operations. (!!) :: Operation -- | Boolean operations. and :: Operation -- | Boolean operations. or :: Operation -- | Groups of operations on similar data. dataOperations :: Operations -- | Data operations. var :: Operation -- | Data operations. missing :: Operation -- | Data operations. missingSome :: Operation -- | Data operations. preserve :: Operation -- | Groups of operations on similar data. miscOperations :: Operations -- | Misc operations. trace :: Operation -- | Groups of operations on similar data. numericOperations :: Operations -- | Numeric operations. (>) :: Operation -- | Numeric operations. (>=) :: Operation -- | Numeric operations. (<) :: Operation -- | Numeric operations. (<=) :: Operation -- | Numeric operations. max :: Operation -- | Numeric operations. min :: Operation -- | Numeric operations. sum :: Operation -- | Numeric operations. (+) :: Operation -- | Numeric operations. (-) :: Operation -- | Numeric operations. (*) :: Operation -- | Numeric operations. (/) :: Operation -- | Numeric operations. (%) :: Operation -- | Groups of operations on similar data. stringOperations :: Operations -- | String operations. cat :: Operation -- | String operations. substr :: Operation -- | Evaluate to a double. evaluateDouble :: Function Double -- | Evaluate to an int. evaluateInt :: Function Int -- | Evaluate to a bool. evaluateBool :: Function Bool -- | Evaluate to an array. evaluateArray :: Function [Json] -- | Evaluate to an object. evaluateObject :: Function JsonObject -- | Evaluate to a string. evaluateString :: Function String module JsonLogic.IO.Type -- | A result is an exception or a value wrapped in IO. type Result r = IO (Either Exception r) -- | A Subevaluator takes a rule and data and returns a result of Json. type SubEvaluator = Rule -> Data -> Result Json -- | A function takes a subevaluator, rule and data and returns a result. type Function r = SubEvaluator -> Rule -> Data -> Result r -- | An operation is a Json function with a name. type Operation = (String, Function Json) -- | Operations is a Map from the operation name to the operation function. type Operations = Map String (Function Json) -- | Throw an evaluation exception. throw :: String -> Result a -- | An evaluation exception thrown by the evaluator or operations. Is used -- in the result type. data Exception -- | Exception thrown when an unknown operation is applied. UnrecognizedOperation :: String -> Exception [operationName] :: Exception -> String -- | Exception thrown when a rule does not contain exactly one operation. InvalidRule :: [String] -> Exception [operationNames] :: Exception -> [String] -- | Exception thrown for any other error. EvalException :: String -> Exception [message] :: Exception -> String module JsonLogic.IO.Operation -- | A map of all the default operations. defaultOperations :: Operations -- | Groups of operations on similar data. arrayOperations :: Operations -- | Array operations. map :: Operation -- | Array operations. reduce :: Operation -- | Array operations. filter :: Operation -- | Array operations. all :: Operation -- | Array operations. none :: Operation -- | Array operations. some :: Operation -- | Array operations. merge :: Operation -- | Array operations. in' :: Operation -- | Groups of operations on similar data. booleanOperations :: Operations -- | Boolean operations. if' :: Operation -- | Boolean operations. (==) :: Operation -- | Boolean operations. (===) :: Operation -- | Boolean operations. (!=) :: Operation -- | Boolean operations. (!==) :: Operation -- | Boolean operations. (!) :: Operation -- | Boolean operations. (!!) :: Operation -- | Boolean operations. and :: Operation -- | Boolean operations. or :: Operation -- | Groups of operations on similar data. dataOperations :: Operations -- | Data operations. var :: Operation -- | Data operations. missing :: Operation -- | Data operations. missingSome :: Operation -- | Data operations. preserve :: Operation -- | Groups of operations on similar data. miscOperations :: Operations -- | Misc operations. trace :: Operation -- | Misc operations. log :: Operation -- | Groups of operations on similar data. numericOperations :: Operations -- | Numeric operations. (>) :: Operation -- | Numeric operations. (>=) :: Operation -- | Numeric operations. (<) :: Operation -- | Numeric operations. (<=) :: Operation -- | Numeric operations. max :: Operation -- | Numeric operations. min :: Operation -- | Numeric operations. sum :: Operation -- | Numeric operations. (+) :: Operation -- | Numeric operations. (-) :: Operation -- | Numeric operations. (*) :: Operation -- | Numeric operations. (/) :: Operation -- | Numeric operations. (%) :: Operation -- | Groups of operations on similar data. stringOperations :: Operations -- | String operations. cat :: Operation -- | String operations. substr :: Operation -- | Evaluate to a double. evaluateDouble :: Function Double -- | Evaluate to an int. evaluateInt :: Function Int -- | Evaluate to a bool. evaluateBool :: Function Bool -- | Evaluate to an array. evaluateArray :: Function [Json] -- | Evaluate to an object. evaluateObject :: Function JsonObject -- | Evaluate to a string. evaluateString :: Function String module JsonLogic.Pure.Evaluator -- | Apply takes a list of operations, a rule and data. And together with -- the default operations evaluates it. -- --
-- >>> apply [] (read "{\"cat\":[\"Hello, \", \"World!\"]}":: Json) JsonNull
-- Right "Hello, World!"
--
apply :: [Operation] -> Rule -> Data -> Result Json
-- | applyEmpty takes a list of operations, a rule and data. And without
-- the default operations evaluates it.
--
--
-- >>> applyEmpty [] (read "{\"cat\":[\"Hello, \", \"World!\"]}":: Json) JsonNull
-- Left (UnrecognizedOperation {operationName = "cat"})
--
applyEmpty :: [Operation] -> Rule -> Data -> Result Json
module JsonLogic.IO.Evaluator
-- | Apply takes a list of operations, a rule and data. And together with
-- the default operations evaluates it.
--
--
-- >>> apply [] (read "{\"cat\":[\"Hello, \", \"World!\"]}":: Json) JsonNull
-- Right "Hello, World!"
--
apply :: [Operation] -> Rule -> Data -> Result Json
-- | applyEmpty takes a list of operations, a rule and data. And without
-- the default operations evaluates it.
--
--
-- >>> applyEmpty [] (read "{\"cat\":[\"Hello, \", \"World!\"]}":: Json) JsonNull
-- Left (UnrecognizedOperation {operationName = "cat"})
--
applyEmpty :: [Operation] -> Rule -> Data -> Result Json