当前位置: 首页>>代码示例>>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;未经允许,请勿转载。