本文整理汇总了TypeScript中collection-utils.mapFirst函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapFirst函数的具体用法?TypeScript mapFirst怎么用?TypeScript mapFirst使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapFirst函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: combineRenderResults
export function combineRenderResults(result: MultiFileRenderResult): SerializedRenderResult {
if (result.size <= 1) {
const first = mapFirst(result);
if (first === undefined) {
return { lines: [], annotations: [] };
}
return first;
}
let lines: string[] = [];
let annotations: Annotation[] = [];
for (const [filename, srr] of result) {
const offset = lines.length + 2;
lines = lines.concat([`// ${filename}`, ""], srr.lines);
annotations = annotations.concat(
srr.annotations.map(ann => ({ annotation: ann.annotation, span: offsetSpan(ann.span, offset) }))
);
}
return { lines, annotations };
}
示例2: emitLeadingComments
protected emitLeadingComments(): void {
if (this.leadingComments !== undefined) {
this.emitCommentLines(this.leadingComments);
return;
}
const topLevelName = defined(mapFirst(this.topLevels));
this.emitMultiline(
`// Example code that deserializes and serializes the model.
// extern crate serde;
// #[macro_use]
// extern crate serde_derive;
// extern crate serde_json;
//
// use generated_module::${topLevelName};
//
// fn main() {
// let json = r#"{"answer": 42}"#;
// let model: ${topLevelName} = serde_json::from_str(&json).unwrap();
// }`
);
}
示例3: emitSourceStructure
protected emitSourceStructure(): void {
// FIXME: Find a good way to do multiple top-levels. Maybe multiple files?
const topLevelType = this.topLevels.size === 1 ? this.schemaForType(defined(mapFirst(this.topLevels))) : {};
const schema = Object.assign({ $schema: "http://json-schema.org/draft-06/schema#" }, topLevelType);
const definitions: { [name: string]: Schema } = {};
this.forEachObject("none", (o: ObjectType, name: Name) => {
const title = defined(this.names.get(name));
definitions[title] = this.definitionForObject(o, title);
});
this.forEachUnion("none", (u, name) => {
if (!this.unionNeedsName(u)) return;
const title = defined(this.names.get(name));
definitions[title] = this.definitionForUnion(u, title);
});
this.forEachEnum("none", (e, name) => {
const title = defined(this.names.get(name));
definitions[title] = this.definitionForEnum(e, title);
});
schema.definitions = definitions;
this.emitMultiline(JSON.stringify(schema, undefined, " "));
}
示例4: 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");
//.........这里部分代码省略.........