本文整理汇总了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;
}
示例2: lookupCookieValue
export function lookupCookieValue(name: string, cookies: Cookie[]): E.Maybe<string> {
return E.mapMaybe(lookupCookie(name, cookies), getValue);
}
示例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)
);
}
示例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>]);
}
示例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)
);
}