module JsonLogic.Pure.Evaluator (apply, applyEmpty) where
import qualified Data.Map as M
import qualified JsonLogic.Evaluator as E
import JsonLogic.Json
import JsonLogic.Pure.Mapping
import JsonLogic.Pure.Operation
import JsonLogic.Pure.Type
apply :: [Operation] -> Rule -> Data -> Result Json
apply :: [Operation] -> Rule -> Rule -> Result Rule
apply [Operation]
ops = [Operation] -> Rule -> Rule -> Result Rule
applyEmpty ([Operation]
ops [Operation] -> [Operation] -> [Operation]
forall a. [a] -> [a] -> [a]
++ Map String (Function Rule) -> [Operation]
forall k a. Map k a -> [(k, a)]
M.toList Map String (Function Rule)
defaultOperations)
applyEmpty :: [Operation] -> Rule -> Data -> Result Json
applyEmpty :: [Operation] -> Rule -> Rule -> Result Rule
applyEmpty [Operation]
ops Rule
rule Rule
dat = Result Identity Rule -> Result Rule
forall r. Result Identity r -> Result r
toResult (Result Identity Rule -> Result Rule)
-> Result Identity Rule -> Result Rule
forall a b. (a -> b) -> a -> b
$ Operations Identity -> Rule -> Rule -> Result Identity Rule
forall (m :: * -> *).
Monad m =>
Operations m -> Rule -> Rule -> Result m Rule
E.apply ((Function Rule -> Function Identity Rule)
-> Map String (Function Rule) -> Operations Identity
forall a b k. (a -> b) -> Map k a -> Map k b
M.map Function Rule -> Function Identity Rule
forall r. Function r -> Function Identity r
fromFunction (Map String (Function Rule) -> Operations Identity)
-> Map String (Function Rule) -> Operations Identity
forall a b. (a -> b) -> a -> b
$ [Operation] -> Map String (Function Rule)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [Operation]
ops) Rule
rule Rule
dat