當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。