• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript collection-utils.iterableSome函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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));
        }
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:42,代码来源:Kotlin.ts


示例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);
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:11,代码来源:Objective-C.ts


示例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(")");
     }
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:14,代码来源:Kotlin.ts


示例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;
    });
开发者ID:nrkn,项目名称:quicktype,代码行数:14,代码来源:FlattenUnions.ts


示例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 };
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:20,代码来源:ExpandStrings.ts


示例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");
//.........这里部分代码省略.........
开发者ID:nrkn,项目名称:quicktype,代码行数:101,代码来源:Objective-C.ts



注:本文中的collection-utils.iterableSome函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript collection-utils.mapFilterMap函数代码示例发布时间:2022-05-24
下一篇:
TypeScript collection-utils.iterableFirst函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap