本文整理汇总了TypeScript中collection-utils.iterableSome函数的典型用法代码示例。如果您正苦于以下问题:TypeScript iterableSome函数的具体用法?TypeScript iterableSome怎么用?TypeScript iterableSome使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterableSome函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: emitHeader
protected emitHeader(): void {
super.emitHeader();
this.emitLine("import com.beust.klaxon.*");
const hasUnions = iterableSome(
this.typeGraph.allNamedTypes(),
t => t instanceof UnionType && nullableFromUnion(t) === null
);
const hasEmptyObjects = iterableSome(
this.typeGraph.allNamedTypes(),
c => c instanceof ClassType && c.getProperties().size === 0
);
if (hasUnions || this.haveEnums || hasEmptyObjects) {
this.emitGenericConverter();
}
let converters: Sourcelike[][] = [];
if (hasEmptyObjects) {
converters.push([[".convert(JsonObject::class,"], [" { it.obj!! },"], [" { it.toJsonString() })"]]);
}
this.forEachEnum("none", (_, name) => {
converters.push([
[".convert(", name, "::class,"],
[" { ", name, ".fromValue(it.string!!) },"],
[' { "\\"${it.value}\\"" })']
]);
});
this.forEachUnion("none", (_, name) => {
converters.push([
[".convert(", name, "::class,"],
[" { ", name, ".fromJson(it) },"],
[" { it.toJson() }, true)"]
]);
});
this.ensureBlankLine();
this.emitLine("private val klaxon = Klaxon()");
if (converters.length > 0) {
this.indent(() => this.emitTable(converters));
}
}
示例2: needsMap
private get needsMap(): boolean {
// TODO this isn't complete (needs union support, for example)
function needsMap(t: Type): boolean {
return (
t instanceof MapType ||
t instanceof ArrayType ||
(t instanceof ClassType && mapSome(t.getProperties(), p => needsMap(p.type)))
);
}
return iterableSome(this.typeGraph.allTypesUnordered(), needsMap);
}
示例3: emitClassDefinitionMethods
protected emitClassDefinitionMethods(c: ClassType, className: Name) {
const isTopLevel = iterableSome(this.topLevels, ([_, top]) => top === c);
if (isTopLevel) {
this.emitBlock(")", () => {
this.emitLine("fun toJson() = mapper.writeValueAsString(this)");
this.ensureBlankLine();
this.emitBlock("companion object", () => {
this.emitLine("fun fromJson(json: String) = mapper.readValue<", className, ">(json)");
});
});
} else {
this.emitLine(")");
}
}
示例4: makeGroupsToFlatten
const groups = makeGroupsToFlatten(nonCanonicalUnions, members => {
messageAssert(members.size > 0, "IRNoEmptyUnions", {});
if (!iterableSome(members, m => m instanceof IntersectionType)) return true;
// FIXME: This is stupid. `flattenUnions` returns true when no more union
// flattening is necessary, but `resolveIntersections` can introduce new
// unions that might require flattening, so now `flattenUnions` needs to take
// that into account. Either change `resolveIntersections` such that it
// doesn't introduce non-canonical unions (by using `unifyTypes`), or have
// some other way to tell whether more work is needed that doesn't require
// the two passes to know about each other.
foundIntersection = true;
return false;
});
示例5: makeEnumInfo
function makeEnumInfo(t: PrimitiveType): EnumInfo | undefined {
const stringTypes = stringTypesForType(t);
const mappedStringTypes = stringTypes.applyStringTypeMapping(stringTypeMapping);
if (!mappedStringTypes.isRestricted) return undefined;
const cases = defined(mappedStringTypes.cases);
if (cases.size === 0) return undefined;
const numValues = iterableReduce(cases.values(), 0, (a, b) => a + b);
if (inference !== "all") {
const keys = Array.from(cases.keys());
if (isAlwaysEmptyString(keys)) return undefined;
const someCaseIsNotNumber = iterableSome(keys, key => /^(\-|\+)?[0-9]+(\.[0-9]+)?$/.test(key) === false);
if (!someCaseIsNotNumber) return undefined;
}
return { cases: new Set(cases.keys()), numValues };
}
示例6: emitSourceStructure
protected emitSourceStructure(proposedFilename: string): void {
const fileMode = proposedFilename !== "stdout";
if (!fileMode) {
// We don't have a filename, so we use a top-level name
const firstTopLevel = defined(mapFirst(this.topLevels));
proposedFilename = this.sourcelikeToString(this.nameForNamedType(firstTopLevel)) + ".m";
}
const [filename, extension] = splitExtension(proposedFilename);
if (this._options.features.interface) {
this.startFile(filename, "h");
if (this.leadingComments !== undefined) {
this.emitCommentLines(this.leadingComments);
} else if (!this._options.justTypes) {
this.emitCommentLines(["To parse this JSON:", ""]);
this.emitLine("// NSError *error;");
this.forEachTopLevel("none", (t, topLevelName) => {
const fromJsonExpression =
t instanceof ClassType
? ["[", topLevelName, " fromJSON:json encoding:NSUTF8Encoding error:&error];"]
: [topLevelName, "FromJSON(json, NSUTF8Encoding, &error);"];
this.emitLine(
"// ",
topLevelName,
" *",
this.variableNameForTopLevel(topLevelName),
" = ",
fromJsonExpression
);
});
}
this.ensureBlankLine();
this.emitLine(`#import <Foundation/Foundation.h>`);
this.ensureBlankLine();
// Emit @class declarations for top-level array+maps and classes
this.forEachNamedType(
"none",
(_: ClassType, className: Name) => this.emitLine("@class ", className, ";"),
(_, enumName) => this.emitLine("@class ", enumName, ";"),
() => null
);
this.ensureBlankLine();
this.ensureBlankLine();
this.emitLine("NS_ASSUME_NONNULL_BEGIN");
this.ensureBlankLine();
if (this.haveEnums) {
this.emitMark("Boxed enums");
this.forEachEnum("leading-and-interposing", (t, n) => this.emitPseudoEnumInterface(t, n));
}
// Emit interfaces for top-level array+maps and classes
this.forEachTopLevel(
"leading-and-interposing",
(t, n) => this.emitNonClassTopLevelTypedef(t, n),
t => !(t instanceof ClassType)
);
const hasTopLevelNonClassTypes = iterableSome(this.topLevels, ([_, t]) => !(t instanceof ClassType));
if (!this._options.justTypes && (hasTopLevelNonClassTypes || this._options.marshallingFunctions)) {
this.ensureBlankLine();
this.emitMark("Top-level marshaling functions");
this.forEachTopLevel(
"leading-and-interposing",
(t, n) => this.emitTopLevelFunctionDeclarations(t, n),
// Objective-C developers get freaked out by C functions, so we don't
// declare them for top-level object types (we always need them for non-object types)
t => this._options.marshallingFunctions || !(t instanceof ClassType)
);
}
this.emitMark("Object interfaces");
this.forEachNamedType("leading-and-interposing", (c: ClassType, className: Name) => this.emitClassInterface(c, className), () => null, () => null);
this.ensureBlankLine();
this.emitLine("NS_ASSUME_NONNULL_END");
this.finishFile();
}
if (this._options.features.implementation) {
this.startFile(filename, extension);
this.emitLine(`#import "${filename}.h"`);
this.ensureBlankLine();
if (!this._options.justTypes) {
this.ensureBlankLine();
this.emitExtraComments("Shorthand for simple blocks");
this.emitLine(`#define Îť(decl, expr) (^(decl) { return (expr); })`);
this.ensureBlankLine();
this.emitExtraComments("nil â NSNull conversion for JSON dictionaries");
this.emitBlock("static id NSNullify(id _Nullable x)", () =>
this.emitLine("return (x == nil || x == NSNull.null) ? NSNull.null : x;")
);
this.ensureBlankLine();
this.emitLine("NS_ASSUME_NONNULL_BEGIN");
//.........这里部分代码省略.........