當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript prelude.mapMaybe函數代碼示例

本文整理匯總了TypeScript中@jonggrang/prelude.mapMaybe函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mapMaybe函數的具體用法?TypeScript mapMaybe怎麽用?TypeScript mapMaybe使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mapMaybe函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: serveFile

export function serveFile(ss: StaticSettings, req: IncomingMessage, file: File): T.Task<StaticResponse> {
  const mLastSent = ifMofiedSince_(req.headers);
  const mdate = P.mapMaybe(file.getModified, H.fromDate);

  function respond(headers: H.ResponseHeaders): T.Task<StaticResponse> {
    return T.pure({
      file,
      headers: cacheControl(ss.maxAge, headers),
      tag: StaticResponseType.FILERESPONSE } as StaticResponse
    );
  }

  const lastMod = P.isJust(mdate) && P.isJust(mLastSent) && mdate.value.equals(mLastSent.value)
    ? T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse)
      : P.isJust(mdate) ? respond({ 'Last-Modified': H.formatHttpDate(mdate.value) })
        : respond({});

  if (ss.useHash) {
    return file.getHash
      .chain(mHash => {
        const lastHash = req.headers['if-none-match'];
        if (lastHash != null && P.isJust(mHash)) {
          const curHash = mHash.value;
          if (ss.weakEtags && (lastHash === curHash || lastHash === `W/${curHash}`
              || `W/${lastHash}` === curHash)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }

          if (!ss.weakEtags && (curHash === lastHash && lastHash.indexOf('W/') !== 0)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }
        }

        if (P.isJust(mHash)) {
          return respond({ 'ETag': mHash.value });
        }
        return lastMod;
      });
  }
  return lastMod;
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:41,代碼來源:static.ts

示例2: lookupCookieValue

export function lookupCookieValue(name: string, cookies: Cookie[]): E.Maybe<string> {
  return E.mapMaybe(lookupCookie(name, cookies), getValue);
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:3,代碼來源:cookie.ts

示例3: ifUnmodifiedSince

function ifUnmodifiedSince(h: H.RequestHeaders, size: number, date1: H.HttpDate): P.Maybe<RspFileInfo> {
  return P.mapMaybe(ifUnmodifiedSince_(h), date2 =>
    date1.equals(date2) ? unConditional(h, size) : rspFileInfo(RspFileInfoType.WITHOUTBODY, 416)
  );
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:5,代碼來源:file.ts

示例4: remove

export function pop<K extends string, V>(k: K, m: StrMap<K, V>): P.Maybe<[V, StrMap<K, V>]> {
  return P.mapMaybe(lookup(k, m), v => [v, remove(k, m)] as [V, StrMap<K, V>]);
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:3,代碼來源:strmap.ts

示例5: ifModified

function ifModified(h: H.RequestHeaders, size: number, d: H.HttpDate): P.Maybe<RspFileInfo> {
  return P.mapMaybe(ifMofiedSince_(h), date =>
    date.equals(d) ? rspFileInfo(RspFileInfoType.WITHOUTBODY, 304) : unConditional(h, size)
  );
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:5,代碼來源:file.ts


注:本文中的@jonggrang/prelude.mapMaybe函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。