         
         return Rule.simple(evaluator: ruleFactory)
     }
-    
 }
 
 extension Sequence where Iterator.Element == (key: String, value: Any) {

    case missing(JSONObject, String)
}

/// A factory that wraps `Component` builder closures (ViewFactoryBuilder, `WrapperFactoryBuilder`, 
/// `ClusterFactoryBuilder` & `RuleFactoryBuilder`) and uses them to produce `Component`s
public final class JSONFactory {
    
    fileprivate enum Key {
        static let structure = "structure"
        static let type = "type"
        static let meta = "meta"
        static let children = "children"
        static let rule = "rule"
        static let and = "AND"
        static let or = "OR"
        static let not = "NOT"
    }
    
    /// A factory closure to build a view `Component`
    public typealias ViewFactoryBuilder = (ComponentMeta?) -> Component
    

        let rules = values.flatMap { JSONFactory.rule(from: $0, using: factory) }
        
        switch rule.key {
        case RuleKey.and where rules.count >= 2:
            return Rule.and(rules: rules)
        case RuleKey.or where rules.count >= 2:
            return Rule.or(rules: rules)
        case RuleKey.not where rules.count == 1:
            return Rule.not(rule: rules[0])
        default:
            return nil
