本文整理匯總了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)
);
}