Takes an array of `types` and flattens them, removing duplicates and
returns a `UnionTypeAnnotation` node containg them.
437642
function createUnionTypeAnnotation(types) {
  var flattened = removeTypeDuplicates(types);

  if (flattened.length === 1) {
    return flattened[0];
  } else {
    return t.unionTypeAnnotation(flattened);
  }
}
1254371
function() {
        return [].slice.call(arguments).reduce(function(a, b) {
          return a.concat(Array.isArray(b) ? funcifyr.flatten.apply(null, b) : b);
        }, []);
      }
339488
protected void mergeTypeDeclarations(TypeDeclaration oldDeclaration,
                                       TypeDeclaration newDeclaration) {
        if (oldDeclaration == null) {
            return;
        }

        //add the missing fields (if any) to newDeclaration
        for (FieldDefinition oldFactField : oldDeclaration.getTypeClassDef().getFieldsDefinitions()) {
            FieldDefinition newFactField = newDeclaration.getTypeClassDef().getField(oldFactField.getName());
            if (newFactField == null) {
                newDeclaration.getTypeClassDef().addField(oldFactField);
            }
        }

        //copy the defined class
        newDeclaration.setTypeClass( oldDeclaration.getTypeClass() );
    }
185754
function fromUnaryType(t) {
    return UnaryType (t.name)
                     (t.url)
                     (t.supertypes)
                     (t._test ([]))
                     (t._extractors.$1);
  }
223158
function mergeAst(schemaAst) {
  var typeDefs = {};

  // Go through the AST and extract/merge type definitions.
  var editedAst = (0, _language.visit)(schemaAst, {
    enter: function enter(node) {
      var nodeName = node.name ? node.name.value : null;

      // Don't transform TypeDefinitions directly
      if (!nodeName || !node.kind.endsWith('TypeDefinition')) {
        return;
      }

      var oldNode = typeDefs[nodeName];

      if (!oldNode) {
        // First time seeing this type so just store the value.
        typeDefs[nodeName] = node;
        return null;
      }

      // This type is defined multiple times, so merge the fields and values.
      var concatProps = ['fields', 'values', 'types'];
      concatProps.forEach(function (propName) {
        if (node[propName] && oldNode[propName]) {
          node[propName] = oldNode[propName].concat(node[propName]);
        }
      });

      typeDefs[nodeName] = node;
      return null;
    }
  });

  var remainingNodesStr = (0, _gqlFormat.formatAst)(editedAst);
  var typeDefsStr = (0, _values2.default)(typeDefs).map(_gqlFormat.formatAst).join('\n');
  var fullSchemaStr = remainingNodesStr + '\n\n' + typeDefsStr;

  return (0, _gqlFormat.formatString)(fullSchemaStr);
}
330162
function flatten(a) {
  return a.reduce(function(flat, val) {
    if (val && typeof val.flatten === 'function') {
      flat = flat.concat(val.flatten());
    }
    else if (Array.isArray(val)) {
      flat = flat.concat(flatten(val));
    }
    else {
      flat.push(val);
    }
    return flat;
  });
}
1000430
function checkType(type,value){
             if(type){
                 if(typeof type == 'string' && type != 'any' &&
                         (type == 'null' ? value !== null : typeof value != type) &&
                         !(value instanceof Array && type == 'array') &&
                         !(value instanceof Date && type == 'date') &&
                         !(type == 'integer' && value%1===0)){
                     return [{property:path,message:(typeof value) + " value found, but a " + type + " is required"}];
                 }
                 if(type instanceof Array){
                     var unionErrors=[];
                     for(var j = 0; j < type.length; j++){ // a union type
                         if(!(unionErrors=checkType(type[j],value)).length){
                             break;
                         }
                     }
                     if(unionErrors.length){
                         return unionErrors;
                     }
                 }else if(typeof type == 'object'){
                     var priorErrors = errors;
                     errors = [];
                     checkProp(value,type,path);
                     var theseErrors = errors;
                     errors = priorErrors;
                     return theseErrors;
                 }
             }
             return [];
         }
918353
function Union () {
  debug('defining new union "type"')

  function UnionType (arg, data) {
    if (!(this instanceof UnionType)) {
      return new UnionType(arg, data)
    }
    debug('creating new union instance')
    var store
    if (Buffer.isBuffer(arg)) {
      debug('using passed-in Buffer instance to back the union', arg)
      assert(arg.length >= UnionType.size, 'Buffer instance must be at least '
          + UnionType.size + ' bytes to back this untion type')
      store = arg
      arg = data
    } else {
      debug('creating new Buffer instance to back the union (size: %d)', UnionType.size)
      store = new Buffer(UnionType.size)
    }

    // set the backing Buffer store
    store.type = UnionType
    this['ref.buffer'] = store

    // initialise the union with values supplied
    if (arg) {
      //TODO: Sanity check - e.g. (Object.keys(arg).length == 1)
      for (var key in arg) {
        // hopefully hit the union setters
        this[key] = arg[key]
      }
    }
    UnionType._instanceCreated = true
  }

  // make instances inherit from `proto`
  UnionType.prototype = Object.create(proto, {
    constructor: {
        value: UnionType
      , enumerable: false
      , writable: true
      , configurable: true
    }
  })

  UnionType.defineProperty = defineProperty
  UnionType.toString = toString
  UnionType.fields = {}

  // comply with ref's "type" interface
  UnionType.size = 0
  UnionType.alignment = 0
  UnionType.indirection = 1
  UnionType.get = get
  UnionType.set = set

  // Read the fields list
  var arg = arguments[0]
  if (typeof arg === 'object') {
    Object.keys(arg).forEach(function (name) {
      var type = arg[name];
      UnionType.defineProperty(name, type);
    })
  }

  return UnionType
}
1021375
function normalizeTypeDescriptors(types) {
  let [requestType, successType, failureType] = types;

  if (typeof requestType === 'string' || typeof requestType === 'symbol') {
    requestType = { type: requestType };
  }

  if (typeof successType === 'string' || typeof successType === 'symbol') {
    successType = { type: successType };
  }
  successType = {
    payload: (action, state, res) => getJSON(res),
    ...successType
  };

  if (typeof failureType === 'string' || typeof failureType === 'symbol') {
    failureType = { type: failureType };
  }
  failureType = {
    payload: (action, state, res) =>
      getJSON(res).then(json => new ApiError(res.status, res.statusText, json)),
    ...failureType
  };

  return [requestType, successType, failureType];
}
853142
def _create_union_types_specification(schema_graph, graphql_types, hidden_classes, base_name):
    """"""
    # When edges point to vertices of type base_name, and base_name is both non-abstract and
    # has subclasses, we need to represent the edge endpoint type with a union type based on
    # base_name and its subclasses. This function calculates what types that union should include.
    def types_spec():
        """Return a list of GraphQL types that this class' corresponding union type includes."""
        return [
            graphql_types[x]
            for x in sorted(list(schema_graph.get_subclass_set(base_name)))
            if x not in hidden_classes
        ]

    return types_spec
889363
def collect_by_type(self, typ):
        '''
        '''
        nodes = []
        if isinstance(self, typ):
            nodes.append(self)
        for c in self:
            nodes.extend(c.collect_by_type(typ))
        return nodes
678056
function TupleTypeAnnotation(node, print) {
  this.push("[");
  print.join(node.types, { separator: ", " });
  this.push("]");
}
827473
function addTypesToUnion(typeSet, types) {
            for (var _i = 0, types_4 = types; _i < types_4.length; _i++) {
                var type = types_4[_i];
                addTypeToUnion(typeSet, type);
            }
        }
624916
function flattenDeep(array) {
      var length = array == null ? 0 : array.length;
      return length ? baseFlatten(array, INFINITY) : [];
    }
66956
def simplify_recursive(typ):
    # type: (AbstractType) -> AbstractType
    """"""
    if isinstance(typ, UnionType):
        return combine_types(typ.items)
    elif isinstance(typ, ClassType):
        simplified = ClassType(typ.name, [simplify_recursive(arg) for arg in typ.args])
        args = simplified.args
        if (simplified.name == 'Dict' and len(args) == 2
                and isinstance(args[0], ClassType) and args[0].name in ('str', 'Text')
                and isinstance(args[1], UnionType) and not is_optional(args[1])):
            # Looks like a potential case for TypedDict, which we don't properly support yet.
            return ClassType('Dict', [args[0], AnyType()])
        return simplified
    elif isinstance(typ, TupleType):
        return TupleType([simplify_recursive(item) for item in typ.items])
    return typ
195984
def p_UnionType(p):
  
  t = [p[2]] + [p[4]] + p[5]
  p[0] = model.UnionType(t=t)
854988
def simplify_types(types):
    # type: (Iterable[AbstractType]) -> List[AbstractType]
    """"""
    flattened = flatten_types(types)
    items = filter_ignored_items(flattened)
    items = [simplify_recursive(item) for item in items]
    items = merge_items(items)
    items = dedupe_types(items)
    # We have to remove reundant items after everything has been simplified and
    # merged as this simplification may be what makes items redundant.
    items = remove_redundant_items(items)
    if len(items) > 3:
        return [AnyType()]
    else:
        return items