当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript maybe.Just函数代码示例

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


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

示例1: pair

    function pair(area: AreaRecord): Maybe<AreaRecord> {
      return Just(area)
        .guard(validate(area));

      function validate(area: AreaRecord): boolean {
        return area.src.length > 0
            && area.src.length === area.dst.length;
      }
    }
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:content.ts

示例2: sep

  function sep(documents: DocumentRecord, area: string): Maybe<AreaRecord[]> {
    return split(area)
      .map(area => ({
        src: find(documents.src, area),
        dst: find(documents.dst, area)
      }))
      .reduce<Maybe<AreaRecord[]>>((acc, area) =>
        acc
          .bind(as =>
            pair(area)
              .fmap(a =>
                concat(as, [a])))
      , Just([]));

    function pair(area: AreaRecord): Maybe<AreaRecord> {
      return Just(area)
        .guard(validate(area));

      function validate(area: AreaRecord): boolean {
        return area.src.length > 0
            && area.src.length === area.dst.length;
      }
    }
  }
开发者ID:falsandtru,项目名称:pjax-api,代码行数:24,代码来源:content.ts

示例3: route

export function route(
  config: Config,
  event: RouterEvent,
  process: Supervisor<'', Error>,
  io: {
    document: Document;
  }
): boolean {
  assert([HTMLAnchorElement, HTMLFormElement, Window].some(Class => event.source instanceof Class));
  switch (event.type) {
    case RouterEventType.click:
    case RouterEventType.submit:
      void savePosition();
      break;
    case RouterEventType.popstate:
      io.document.title = loadTitle();
      break;
  }
  return Just(0)
    .guard(validate(event.request.url, config, event))
    .bind(() =>
      scope(config, (({ orig, dest }) => ({ orig: orig.pathname, dest: dest.pathname }))(event.location)))
    .fmap(async config => {
      void event.original.preventDefault();
      void process.cast('', new Error(`Aborted.`));
      const cancellation = new Cancellation<Error>();
      const kill = process.register('', e => {
        void kill();
        void cancellation.cancel(e);
        return new Promise<never>(() => undefined);
      }, undefined);
      const [scripts] = await env;
      window.history.scrollRestoration = 'manual';
      //void progressbar(config.progressbar);
      return router(config, event, { process: cancellation, scripts }, io)
        .then(m => m
          .fmap(async ([ss, p]) => (
            void kill(),
            void docurl.sync(),
            void ss
              .filter(s => s.hasAttribute('src'))
              .forEach(s =>
                void scripts.add(new URL(standardize(s.src)).reference)),
            void (await p)
              .filter(s => s.hasAttribute('src'))
              .forEach(s =>
                void scripts.add(new URL(standardize(s.src)).reference))))
          .extract())
        .catch(reason => (
          void kill(),
          void docurl.sync(),
          window.history.scrollRestoration = 'auto',
          !cancellation.canceled || reason instanceof FatalError
            ? void config.fallback(currentTargets.get(event.original) as RouterEventSource, reason)
            : undefined));
    })
    .extract(
      () => {
        switch (event.type) {
          case RouterEventType.click:
          case RouterEventType.submit:
            break;
          case RouterEventType.popstate:
            if (!isHashChange(event.location.dest)) {
              void config.fallback(event.source, new Error(`Disabled.`));
              return true;
            }
            break;
        }
        void docurl.sync();
        return false;
      },
      () => true);
}
开发者ID:falsandtru,项目名称:pjax-api,代码行数:74,代码来源:router.ts

示例4: Just

 .map<Maybe<Config>>(option =>
   option
     ? Just(new Config(extend<Option>({}, config, option)))
     : Nothing)
开发者ID:falsandtru,项目名称:pjax-api,代码行数:4,代码来源:scope.ts

示例5: Just

 .extract(f => html => Just(f(html)));
开发者ID:falsandtru,项目名称:pjax-api,代码行数:1,代码来源:html.ts


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