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

TypeScript highland类代码示例

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

本文整理汇总了TypeScript中highland的典型用法代码示例。如果您正苦于以下问题:TypeScript highland类的具体用法?TypeScript highland怎么用?TypeScript highland使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了highland类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: readFromFile

export function readFromFile(fileName: string, callback: (inst: Instruction) => void) {

    var consumeInstructionPartial = _.partial<InstructionConsumer[], InstructionConsumerArgs, void>(
        consumeInstruction,
        [consumeNil, consumeDelay, consumeCommand]
    );

    highland([fileName])
    .flatMap(highland.wrapCallback(fs.readFile) as any)
    .split()
    .filter((line: string) => {
        return line !== '';
    })
    .map((line: string) => {
        return line.split(' ');
    })
    .map<Instruction | undefined | Highland.Nil>(
        _.partial<InstructionParser[], string[], Instruction | undefined>(parseInstruction, [parseSleep, parseMotion])
    )
    .consume((err: Error, instruction: Instruction | Highland.Nil, push: Function, next: Function) => {
        consumeInstructionPartial({
            err: err,
            instruction: instruction,
            push: push,
            next: next
        });
    })
    .each((val: any) => {
        callback(val);
    });
}
开发者ID:gsanta,项目名称:r0,代码行数:31,代码来源:readFromFile.ts


示例2: hl

 .flatMap(function(gpmlState) {
   return hl(getGPMLElementByGraphId(gpmlState.GraphRef)).map(function(
     gpmlDataNode
   ) {
     return fillInGPMLPropertiesFromParent(gpmlDataNode, gpmlState);
   });
 })
开发者ID:wikipathways,项目名称:gpml2pvjson-js,代码行数:7,代码来源:toPvjson.ts


示例3: VError

    .flatMap(function(
      pvjsonEntity: PvjsonNode | PvjsonEdge
    ): Highland.Stream<
      | {
        pathway: Pathway | PathwayStarter;
        entitiesById: PvjsonEntitiesById;
      }
      | Error
    > {
      const { id, zIndex } = pvjsonEntity;

      // TODO we might want to sort by other criteria, such as
      // to order a State above its DataNode, which would be
      // ordered above its Group, if any
      const insertEntityIdAndSortByZIndex = flow([
        insertIfNotExists(id),
        sortByZIndex
      ]);

      let finalSortedStream;
      if (isPvjsonEdgeOrBurr(pvjsonEntity)) {
        const isAttachedTo = pvjsonEntity.isAttachedTo;
        arrayify(isAttachedTo).forEach(function(graphRef: string) {
          const graphRefs = graphIdsByGraphRef[graphRef] || [];
          if (graphRefs.indexOf(id) === -1) {
            graphRefs.push(id);
          }
          graphIdsByGraphRef[graphRef] = graphRefs;
        });

        if (isPvjsonBurr(pvjsonEntity)) {
          finalSortedStream = hl(
            getPvjsonEntityLatestByGraphId(isAttachedTo)
          ).map(function(
            referencedEntity: PvjsonSingleFreeNode | PvjsonGroup | PvjsonEdge
          ) {
            if (isPvjsonNode(referencedEntity)) {
              const { attachmentDisplay } = pvjsonEntity;
              const [
                relativeOffsetScalarX,
                relativeOffsetScalarY
              ] = attachmentDisplay.relativeOffset;
              attachmentDisplay.offset = [
                relativeOffsetScalarX * referencedEntity.width,
                relativeOffsetScalarY * referencedEntity.height
              ];
              pvjsonEntity.attachmentDisplay = omit(
                ["relativeOffset"],
                attachmentDisplay
              );
            }
            setPvjsonEntity(pvjsonEntity);

            // NOTE: burrs are not added to the property "contained".
            // Rather, they are added to the property "burrs".
            referencedEntity.burrs = referencedEntity.burrs || [];
            insertEntityIdAndSortByZIndex(referencedEntity.burrs);
            setPvjsonEntity(referencedEntity);

            return processor.output;
          });
        } else if (isPvjsonEdge(pvjsonEntity)) {
          try {
            const pvjsonEdge = postprocessEdgePVJSON(
              processor.output.entitiesById as {
                [key: string]: PvjsonNode | PvjsonEdge;
              },
              pvjsonEntity
            );
            processor.output = iassign(
              processor.output,
              function(o) {
                return o.pathway.contains;
              },
              insertEntityIdAndSortByZIndex
            );

            setPvjsonEntity(pvjsonEdge);

            finalSortedStream = hl([processor.output]);
          } catch (err) {
            return hl.fromError(err);
          }
        } else {
          return hl.fromError(
            new VError(
              `
		Unexpected entity type.
		Only Edge or Burr should return true for
		isPvjsonEdgeOrBurr(
			${JSON.stringify(pvjsonEntity, null, "  ")}
		)
		`
            )
          );
        }
      } else if (isPvjsonGroup(pvjsonEntity)) {
        // We still have some GPML files with empty Groups and/or nested Groups
        // floating around, but we don't process them, because that's a
        // curation issue, not a gpml2pvjson issue.
//.........这里部分代码省略.........
开发者ID:wikipathways,项目名称:gpml2pvjson-js,代码行数:101,代码来源:toPvjson.ts


示例4: toPvjson

export function toPvjson(
  inputStreamWithMessedUpRDFIDs: NodeJS.ReadableStream,
  pathwayIri?: string
) {
  // NOTE: GPML2013a incorrectly uses "rdf:id" instead of "rdf:ID".
  // We need to fix this error so that CXML can process the GPML.
  const inputStream = hl(inputStreamWithMessedUpRDFIDs)
    .splitBy(' rdf:id="')
    .intersperse(' rdf:ID="');

  const selectorToCXML = {
    // TODO why does TS require that we use the Pathway's "constructor.prototype"
    // instead of just the Pathway?
    // Why does Pathway.Graphics not need that?
    // Why do many of the other require using the prototype?
    //
    "/Pathway/@*": GPML2013a.document.Pathway.constructor.prototype,
    "/Pathway/Comment": GPML2013a.document.Pathway.Comment[0],
    "/Pathway/Graphics/@*": GPML2013a.document.Pathway.Graphics,
    "/Pathway/DataNode": GPML2013a.DataNodeType.prototype,
    "/Pathway/State": GPML2013a.StateType.prototype,
    "/Pathway/Interaction": GPML2013a.InteractionType.prototype,
    "/Pathway/GraphicalLine": GPML2013a.GraphicalLineType.prototype,
    "/Pathway/Label": GPML2013a.LabelType.prototype,
    "/Pathway/Shape": GPML2013a.ShapeType.prototype,
    "/Pathway/Group": GPML2013a.GroupType.prototype,
    "/Pathway/InfoBox": GPML2013a.InfoBoxType.prototype,
    "/Pathway/Legend": GPML2013a.LegendType.prototype,
    "/Pathway/Biopax/bp:PublicationXref":
      GPML2013a.document.Pathway.Biopax.PublicationXref[0],
    "/Pathway/Biopax/bp:openControlledVocabulary":
      GPML2013a.document.Pathway.Biopax.openControlledVocabulary[0]
  };

  const cxmlXPath = new CXMLXPath(inputStream, GPML2013a, {
    bp: "http://www.biopax.org/release/biopax-level3.owl#"
    //rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  });

  const cxmlSources = cxmlXPath.parse(selectorToCXML);

  const processor = new Processor(
    GPML2013aKeyMappings,
    GPML2013aKeyValueMappings,
    GPML2013aValueMappings,
    GPML2013aValueConverters
  );
  const {
    fillInGPMLPropertiesFromParent,
    getPvjsonEntityLatestByGraphId,
    graphIdsByGraphRef,
    graphIdToZIndex,
    getGPMLElementByGraphId,
    preprocessGPMLElement,
    processGPMLAndPropertiesAndType,
    processProperties,
    processPropertiesAndType,
    setPvjsonEntity
  } = processor;

  if (pathwayIri) {
    processor.output = iassign(
      processor.output,
      function(o) {
        return o.pathway;
      },
      function(pathway) {
        pathway.id = pathwayIri;
        return pathway;
      }
    );
  }

  const sortByZIndex = sortByMap(graphIdToZIndex);

  const pathwayMetadataStream = hl([
    cxmlSources["/Pathway/@*"].doto(function(pathway) {
      if (supportedNamespaces.indexOf(pathway._namespace) === -1) {
        // TODO should we do anything further?
        throw new Error(`Unsupported namespace: ${pathway._namespace}`);
      }
    }),
    cxmlSources["/Pathway/Graphics/@*"]
  ])
    .merge()
    .map(processProperties)
    .reduce({} as Record<string, any>, function(acc, metadataChunk) {
      return assign(acc, metadataChunk);
    })
    // there should only be one item through this last step
    .map(function(metadata: Record<string, any>) {
      processor.output = iassign(
        processor.output,
        function(o) {
          return o.pathway;
        },
        function(pathway): Pathway {
          const mergedPathway = assign(pathway, metadata);
          // NOTE: GPML schema specifies that name is required
          const { name } = mergedPathway;
//.........这里部分代码省略.........
开发者ID:wikipathways,项目名称:gpml2pvjson-js,代码行数:101,代码来源:toPvjson.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript http-errors类代码示例发布时间:2022-05-28
下一篇:
TypeScript helmet类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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