creates type wrapper for list of given type
760612
def _create_list_of_wrapper(name, t):
    ''
    def __new__(cls, json_data, selection_list=None):
        if json_data is None:
            return None
        return [t(v, selection_list) for v in json_data]

    def __to_graphql_input__(value, indent=0, indent_string='  '):
        r = []
        for v in value:
            r.append(t.__to_graphql_input__(v, indent, indent_string))
        return '[' + ', '.join(r) + ']'

    def __to_json_value__(value):
        if value is None:
            return None
        return [t.__to_json_value__(v) for v in value]

    return type(name, (t,), {
        '__new__': __new__,
        '_%s__auto_register' % name: False,
        '__to_graphql_input__': __to_graphql_input__,
        '__to_json_value__': __to_json_value__,
    })
661775
def make_list(obj, cast=True):
    
    if isinstance(obj, list):
        return list(obj)
    if isinstance(obj, types.GeneratorType):
        return list(obj)
    if isinstance(obj, (tuple, set)) and cast:
        return list(obj)
    else:
        return [obj]
207127
def as_list(callable):
    """"""
    @wraps(callable)
    def wrapper(value_iter):
        return [callable(value) for value in value_iter]

    return wrapper
564694
@SuppressWarnings("all")
    public static <T> List<T> toTypedList(Object data, Class<T> type) {
        List<T> listResult = new ArrayList<>();
        if (data == null) {
            return listResult;
        }
        if (data instanceof Collection) {
            Collection collection = (Collection) data;
            for (Object o : collection) {
                listResult.add(Reflection.toType(o, type));
            }
            return listResult;
        }
        if (data.getClass().isArray()) {
            for (Object o : ArrayUtil.toObjectArray(data)) {
                listResult.add(Reflection.toType(o, type));
            }
            return listResult;
        }
        listResult.add(Reflection.toType(data, type));
        return listResult;
    }
243320
def wrap(cls, e, stack_depth=0):
        
        if e == None:
            return Null
        elif isinstance(e, (list, Except)):
            return e
        elif is_data(e):
            e.cause = unwraplist([Except.wrap(c) for c in listwrap(e.cause)])
            return Except(**e)
        else:
            tb = getattr(e, '__traceback__', None)
            if tb is not None:
                trace = _parse_traceback(tb)
            else:
                trace = _extract_traceback(0)

            cause = Except.wrap(getattr(e, '__cause__', None))
            if hasattr(e, "message") and e.message:
                output = Except(context=ERROR, template=text_type(e.message), trace=trace, cause=cause)
            else:
                output = Except(context=ERROR, template=text_type(e), trace=trace, cause=cause)

            trace = extract_stack(stack_depth + 2)  # +2 = to remove the caller, and it's call to this' Except.wrap()
            output.trace.extend(trace)
            return output
1205682
private static String getTypeInfo(List<Object> list) {

        StringBuilder s = new StringBuilder();
        for (Object o : list) {
            if (s.length() > 0)
                s.append(", ");
            if (o == null)
                s.append("null");
            else {
                s.append(o.getClass().getName());
                s.append("=");
                s.append(o);
            }
        }
        return s.toString();
    }
598276
@Deprecated
    private static ListAttributeDefinition wrapAsList(final AttributeDefinition def) {
        final ListAttributeDefinition list = new ListAttributeDefinition(new SimpleListAttributeDefinition.Builder(def.getName(), def)
                .setElementValidator(def.getValidator())) {


            @Override
            public ModelNode getNoTextDescription(boolean forOperation) {
                final ModelNode model = super.getNoTextDescription(forOperation);
                setValueType(model);
                return model;
            }

            @Override
            protected void addValueTypeDescription(final ModelNode node, final ResourceBundle bundle) {
                setValueType(node);
            }

            @Override
            public void marshallAsElement(final ModelNode resourceModel, final boolean marshalDefault, final XMLStreamWriter writer) throws XMLStreamException {
                throw new RuntimeException();
            }

            @Override
            protected void addAttributeValueTypeDescription(ModelNode node, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
                setValueType(node);
            }

            @Override
            protected void addOperationParameterValueTypeDescription(ModelNode node, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
                setValueType(node);
            }

            private void setValueType(ModelNode node) {
                node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
            }
        };
        return list;
    }
624685
def list_deep_types(list_):
    
    type_list = []
    for item in list_:
        if util_type.is_listlike(item):
            type_list.extend(list_deep_types(item))
        else:
            type_list.append(type(item))
    return type_list
1087699
static TypeParameterTree typeParameterInList(
      List<? extends TypeParameterTree> typeParameters, Symbol v) {
    return typeParameters.stream()
        .filter(t -> t.getName().contentEquals(v.name))
        .collect(MoreCollectors.onlyElement());
  }
647059
def wrap(v):
    

    type_ = _get(v, CLASS)

    if type_ is dict:
        m = object.__new__(Data)
        _set(m, SLOT, v)
        return m
    elif type_ is none_type:
        return Null
    elif type_ is list:
        return FlatList(v)
    elif type_ in generator_types:
        return FlatList(list(unwrap(vv) for vv in v))
    else:
        return v
358278
public List<Type> closure(Type t) {
        List<Type> cl = closureCache.get(t);
        if (cl == null) {
            Type st = supertype(t);
            if (!t.isCompound()) {
                if (st.hasTag(CLASS)) {
                    cl = insert(closure(st), t);
                } else if (st.hasTag(TYPEVAR)) {
                    cl = closure(st).prepend(t);
                } else {
                    cl = List.of(t);
                }
            } else {
                cl = closure(supertype(t));
            }
            for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail)
                cl = union(cl, closure(l.head));
            closureCache.put(t, cl);
        }
        return cl;
    }
549981
def create_list_int(help_string=NO_HELP, default=NO_DEFAULT):
        # type: (str, Union[List[int], NO_DEFAULT_TYPE]) -> List[int]
        
        # noinspection PyTypeChecker
        return ParamFunctions(
            help_string=help_string,
            default=default,
            type_name="List[int]",
            function_s2t=convert_string_to_list_int,
            function_t2s=convert_list_int_to_string,
        )
1170638
function(list, type) {
            if (!isArray(list.value))
                return list;

            function flatten_(list) {
                return list.reduce(function(a, b) {
                    return a.concat(isArray(b.value)
                        ? flatten_(b.value) : b);
                }, []);
            }

            // TODO: should not it try to determine the default return type by the type
            // of the input list top dimension? (for consistency with `cat`?)

            var ReturnType = type ? {
                comma: Value,
                space: Expression,
                ",":   Value,
                " ":   Expression
            }[type.value] : Value;

            if (!ReturnType) throw {
                type:    "Argument",
                message: "invalid `" + type.toCSS()
                    + "` delimiter. Expected `comma`, `space`, `,` or ` `\n"
            };

            return new ReturnType(flatten_(list.value));
        }
566640
def _wrap_result(self, func):
        
        def wrapper(*args):
            result = func(*args)
            if hasattr(result, '__iter__') and not isinstance(result, etree._Element):
                return [self._wrap_element(element) for element in result]
            else:
                return self._wrap_element(result)
        return wrapper
681478
def _type_container(self, value, _type):
        '  '
        if value is None:
            # normalize null containers to empty list
            return []
        elif not isinstance(value, list):
            raise ValueError("expected list type, got: %s" % type(value))
        else:
            return sorted(self._type_single(item, _type) for item in value)
177356
def create(type_dict, *type_parameters):
    
    assert len(type_parameters) == 1
    klazz = TypeFactory.new(type_dict, *type_parameters[0])
    assert isclass(klazz)
    assert issubclass(klazz, Object)
    return TypeMetaclass('%sList' % klazz.__name__, (ListContainer,), {'TYPE': klazz})
1310631
function makeTypeChecker(freeTypeVars) {
		if (!freeTypeVars)
			freeTypeVars = []

		var bound_type_params = new Map
		var bound_nodes = []
		freeTypeVars.forEach(function(tp) {
			bound_type_params.put(tp.name, [])
		})

		var callSigMatches = []

		function isPrtyCompatibleWithType(prty, type, path, receiver) {
			if (prty.type === 'node') {
				return isNodeCompatibleWithType(prty.node, type, path, receiver)
			} else {
				var ok = prty.types.some(function(t) {
					return isTypeCompatibleWithType(t, type, null)
				})
				if (!ok) {
					reportError(path, 'expected ' + formatType(type) + ' but found ' + formatUnion(prty.types))
				}
				return ok
			}
		}
		var node_prty_compatible = Object.create(null)
		function isNodeCompatibleWithProperty(node, k, prty, path, receiver) {
			if (prty.meta.origin === LIB_ORIGIN) // there are too many non-portable properties in lib.d.ts
				return true
			if (!receiver)
				receiver = node
			node = node.rep()
			if (node.isAny)
				return true
			if (node.isFree) {
				bound_nodes.push({type: 'type', node: node, bound: prty.type})
				return true
			}
			var name = node.translateName(k)
			var dst = node.properties.get(name)
			if (dst) {
				return isPrtyCompatibleWithType(dst, prty.type, path, receiver)
			} else {
				var protoWithPrty = node.prototypes.filter(function(proto) {
					return proto.properties.has(name)
				})
				protoWithPrty = protoWithPrty.unique(function(proto) { return proto.rep().id })
				if (protoWithPrty.length === 0) {
					if (!prty.optional) {
						reportError(path, 'expected ' + formatType(prty.type) + ' but found nothing')
						return false
					}
					return true
				} else if (protoWithPrty.length === 1) {
					return isPrtyCompatibleWithType(protoWithPrty[0].properties.get(name), prty.type, path, receiver)
				} else {
					var h = node.id + '~' + k + '~' + prty.optional + '.' + canonicalizeType(prty.type)
					if (h in node_prty_compatible)
						return node_prty_compatible[h]
					node_prty_compatible[h] = false	
					var ok = node.prototypes.some(function(proto) {
						return isNodeCompatibleWithProperty(proto, k, prty, null, receiver)
					})
					if (!ok) {
						reportError(path, 'expected ' + prty.type + ' but found [complex type]')
					}
					node_prty_compatible[h] = ok
					return ok
				}
			}
		}
		var node_type_compatible = Object.create(null)
		function isNodeCompatibleWithType(node, type, path, receiver, continueOnError) {
			node = node.rep()
			if (node.isAny) {
				return true
			}
			if (node.isFree) {
				bound_nodes.push({type: 'type', node: node, bound: type})
				return true
			}
			var h = canonicalizeType(type) + "~" + node.id // TODO: include receiver??
			if (h in node_type_compatible) {
				return node_type_compatible[h]
			}
			node_type_compatible[h] = true
			return node_type_compatible[h] = isNodeCompatibleWithTypeX(node, type, path, receiver, continueOnError)
		}
		function isNodeCompatibleWithTypeX(node, type, path, receiver, continueOnError) {
			node = node.rep()
			if (node.isAny || node.primitives.has({type:'value', value:null}))
				return true
			var originalType = type
			if (type.type === 'reference')
				type = resolveTypeRef(type)
			switch (type.type) {
				case 'object':
					var ok = true
					if (!node.isObject) {
						reportError(path, 'expected ' + formatType(originalType) + ' but found ' + formatNodeAsPrimitive(node))
						ok = false
						return false
					}
					if (type.brand && isValidBrand(type.brand)) {
						var hasBrand = !node.brands.isEmpty()
						ok = node.brands.some(type.brand)
						if (!ok) {
							ok = node.prototypes.some(function(proto) {
								return hasBrand |= proto.brands.some(type.brand)
							})
						}
						if (!ok) {
							if (hasBrand) {
								reportError(path, 'expected ' + type.brand + ' but found ' + formatNode(node) + ' [BRAND]')
							} else {
								reportError(path, 'missing prototype for branded type ' + type.brand)
							}
						}
						if (!continueOnError)
							return ok // defer checking of other properties to the constructor check
					}
					for (var k in type.properties) {
						if (!isNodeCompatibleWithProperty(node, k, type.properties[k], qualify(path,k))) {
							ok = false 
							if (!continueOnError) return false
						}
					}
					if (type.numberIndexer) {
						ok &= node.properties.all(function(name,dst) {
							if (!isNumberString(name))
								return true
							return isPrtyCompatibleWithType(dst, type.numberIndexer, qualify(path,'[' + name + ']'), node)
						})
						if (!ok && !continueOnError) return false
					}
					if (type.stringIndexer) {
						ok &= node.properties.all(function(name,dst) {
							// FIXME: enumerability check?
							return isPrtyCompatibleWithType(dst, type.stringIndexer, qualify(path, "['" + name + "']"), node)
						})
						if (!ok && !continueOnError) return false
					}
					if (type.calls.length > 0 && node.functions.isEmpty() && node.call_sigs.isEmpty()) {
						reportError(path, 'expected ' + formatTypeCall(type.calls[0]) + ' but found non-function object')
						ok = false
						if (!continueOnError) return false
					}
					type.calls.forEach(function(sig) {
						callSigMatches.push({
							callsig: sig,
							node: node,
							receiver: receiver,
							path: path
						})
					})
					return ok
				case 'enum':
					var enum_vals = enum_values.get(type.name)
					if (enum_vals.length === 0) {
						return true
					}
					var ok = enum_vals.some(function(v) {
						return isNodeCompatibleWithValue(node, v)
					})
					if (!ok) {
						reportError(path, 'expected ' + type.name + ' but found ' + formatNodeAsPrimitive(node))
					}
					return ok
				case 'any':
				case 'void':
					return true
				case 'number':
				case 'string':
				case 'boolean':
					if (node.primitives.has({type: type.type}))
						return true
					var ok = node.primitives.some(function(t) {
						return t.type === 'value' && typeof t.value === type.type
					})
					if (!ok) {
						reportError(path, 'expected ' + formatType(type) + ' but found ' + formatNodeAsPrimitive(node))
					}
					return ok
				case 'string-const':
					if (node.primitives.has({type: 'value', value: type.value}))
						return true
					if (node.primitives.has({type: 'string'}))
						return true
					reportError(path, 'expected ' + formatType(type) + ' but found ' + formatNodeAsPrimitive(node))
					return false
				case 'node':
					bound_nodes.push({type: 'node', node: type.node, bound: node})
					return true
				case 'type-param':
					if (!bound_type_params.has(type.name))
						throw new Error("Unbound type parameter " + type.name)
					// TODO: check constraint
					bound_type_params.push(type.name, {type: 'node', node: node})
					return true
				case 'opaque-type':
					if (node.primitives.has(type)) {
						return true
					} else {
						reportError(path, "expected generic type " + type.name + " but found " + formatNode(node))
						return false
					}
				default:
					throw new Error("Unexpected type: " + util.inspect(type))
			}
			return true
		}
		function isNodeCompatibleWithValue(node, v) {
			node = node.rep()
			if (v === null)
				return true
			if (v && typeof v === 'object')
				return node === getConcreteObject(v.key)
			if (node.primitives.has({type:'value', value:v}))
				return true
			switch (typeof v) {
				case 'number':
					return node.primitives.has({type:'number'})
				case 'string':
					return node.primitives.has({type:'string'})
				case 'boolean':
					return node.primitives.has({type:'boolean'})
				case 'undefined':
					return node.primitives.has({type:'void'})
				default:
					throw new Error("Unexpected value: " + util.inspect(v))
			}
		}
		var type2type_compatible = Object.create(null)
		function isTypeCompatibleWithType(t1, t2, path, continueOnError) {
			if (t1.type === 'reference' || t2.type === 'reference') {
				var h = canonicalizeType(t1) + '~' + canonicalizeType(t2)
				if (h in type2type_compatible)
					return type2type_compatible[h]
				type2type_compatible[h] = true
				return type2type_compatible[h] = isTypeCompatibleWithTypeX(t1, t2, path, continueOnError)
			}
			return isTypeCompatibleWithTypeX(t1, t2, path, continueOnError)
		}
		function isTypeCompatibleWithTypeX(t1, t2, path, continueOnError) {
			if (t1.type === 'any' || t2.type === 'any')
				return true
			if (t1.type === 'node')
				return isNodeCompatibleWithType(t1.node, t2, path)
			if (t1.type === 'reference' && t2.type === 'reference' && t1.name === t2.name) {
				// Approximate compatibility check on references by simply checking type arguments
				// This not technically not a compatibility check between structural types, but
				// I will expect it will produce more useful error messages, 
				// e.g. "expected string[] but found number[]" 
				var ok = t1.typeArguments.all(function(p1, i) {
					return isTypeCompatibleWithType(p1, t2.typeArguments[i], null)
				})
				if (!ok) {
					reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
				}
				return ok
			}
			if (t1.type === 'reference' && t2.type === 'reference') {
				// expand both references, but cut off the path here, so we don't report
				// a complicated message describing why the two references are incompatible
				// e.g. "expected Promise but found HttpRequest" instead of unfolding both types in the error message
				var ok = isTypeCompatibleWithType(resolveTypeRef(t1), resolveTypeRef(t2), null)
				if (!ok) {
					reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
				}
				return ok
			}
			if (t2.type === 'reference')
				t2 = resolveTypeRef(t2)
			if (t2.type === 'object' && (t1.type !== 'object' && t1.type !== 'reference')) {
				// Coerce t1 to an object. If the compatibility check fails, report the error
				// as simply "expected XX but found number" instead of a complicated message resulting from
				// a structural compatibility check
				var t1o = coerceTypeToObject(t1)
				if (t1o.type === 'object' || t1o.type === 'reference') {
					var ok = isTypeCompatibleWithType(t1o, t2, null)
					if (!ok) {
						reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
					}
					return ok
				}
			}
			switch (t2.type) {
				case 'object':
					var original_t1 = t1
					if (t1.type === 'opaque-type' && t1.constraint)
						t1 = t1.constraint
					if (t1.type === 'reference')
						t1 = resolveTypeRef(t1)
					if (t1.type !== 'object') {
						reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(original_t1))
						return false
					}
					var ok = true
					for (var k in t2.properties) {
						if (t1.properties.hasOwnProperty(k)) {
							if (!isTypeCompatibleWithType(t1.properties[k].type, t2.properties[k].type, qualify(path,k))) {
								ok = false
								if (!continueOnError) {
									return false
								}
							}
						}
						else if (t1.numberIndexer && isNumberString(k)) {
							if (!isTypeCompatibleWithType(t1.numberIndexer, t2.properties[k].type, qualify(path, k))) {
								ok = false
								if (!continueOnError)
									return false
							}
						}
						else if (t1.stringIndexer) {
							if (!isTypeCompatibleWithType(t1.stringIndexer, t2.properties[k].type, qualify(path, k))) {
								ok = false
								if (!continueOnError)
									return false
							}	
						}
						else {
							if (!t2.properties[k].optional) {
								reportError(qualify(path,k), 'expected ' + formatType(t2) + ' but found nothing')
								ok = false
								if (!continueOnError)
									return false
							}
						}
					}
					if (t2.numberIndexer) {
						for (var k in t1.properties) {
							if (isNumberString(k)) {
								if (!isTypeCompatibleWithType(t1.properties[k].type, t2.numberIndexer, qualify(path, k))) {
									ok = false
									if (!continueOnError)
										return false
								}
							}
						}
						if (t1.numberIndexer) {
							if (!isTypeCompatibleWithType(t1.numberIndexer, t2.numberIndexer, qualify(path, '[number]'))) {
								ok = false
								if (!continueOnError)
									return false
							}
						}
					}
					if (t2.stringIndexer) {
						for (var k in t1.properties) {
							// TODO: enumerability check?
							if (!isTypeCompatibleWithType(t1.properties[k].type, t2.stringIndexer, qualify(path, k))) {
								ok = false
								if (!continueOnError)
									return false
							}
						}
						if (t1.stringIndexer) {
							if (!isTypeCompatibleWithType(t1.stringIndexer, t2.stringIndexer, qualify(path, '[number]'))) {
								ok = false
								if (!continueOnError)
									return false
							}
						}
					}
					// TODO: calls, brands?
					return ok
				case 'number':
				case 'string':
				case 'boolean':
					var ok = t1.type === t2.type || (t1.type === 'value' && typeof t1.value === t2.type)
					if (!ok) {
						reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
					}
					return ok
				case 'string-const':
					var ok = t1.type === 'string' || (t1.type === 'value' && t1.value === t2.value)
					if (!ok) {
						reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
					}
					return ok
				case 'value':
					var ok = (t1.type === typeof t2.value) || (t1.type === 'value' && t1.value === t2.value)
					if (!ok) {
						reportError(path, 'expected ' + formatType(t2) + ' but found ' + formatType(t1))
					}
					return ok
				case 'enum':
					return true // TODO: check enum type properly
				case 'void':
					return true
				case 'node':
					bound_nodes.push({type: 'type', node: t2.node, bound: t1})
					return true
				case 'type-param':
					if (!bound_type_params.has(t2.name))
						throw new Error("Unbound type parameter " + t2.name)
					// TODO: check constraint
					bound_type_params.push(t2.name, {type: 'type', bound: t1})
					return true
				case 'opaque-type':
					if (t1.type === 'opaque-type' && t1.name === t2.name)
						return true
					reportError(path, 'expected generic type ' + t2.name + ' but found ' + formatType(t1))
					return false
				case 'type-param':
					throw new Error
				default:
					throw new Error("Unexpected type: " + t2.type)
			}
		}
		function isCallCompatibleWithCall(incall, outcall) {
			// TODO: variadic
			incall = widenPolymorphicCallSig(incall) // just approximate tests for polymorphic functions (TODO: proper type check)
			outcall = widenPolymorphicCallSig(outcall)

			// Check that the parameters to outcall can be used in a valid call to incall
			for (var i=0; i<incall.parameters.length; ++i) {
				var iparm = incall.parameters[i]
				if (i < outcall.parameters.length) {
					var oparm = outcall.parameters[i]
					if (!isTypeCompatibleWithType(oparm.type, iparm.type, null, false)) {
						return false
					}
				} else if (!iparm.optional) {
					return false
				}
			}

			// Check that return type from incall is a valid return type from outcall
			return isTypeCompatibleWithType(incall.returnType, outcall.returnType, null, false)
		}
		return {
			isTypeCompatibleWithType: isTypeCompatibleWithType,
			isNodeCompatibleWithType: isNodeCompatibleWithType,
			isPrtyCompatibleWithType: isPrtyCompatibleWithType,
			isNodeCompatibleWithProperty: isNodeCompatibleWithProperty,
			isCallCompatibleWithCall: isCallCompatibleWithCall,
			getBoundTypeParams: function() { return bound_type_params },
			getBoundNodes: function() { return bound_nodes },
			getCallSigMatches: function() { return callSigMatches },
		}
	}