本文整理匯總了TypeScript中@jonggrang/prelude.left函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript left函數的具體用法?TypeScript left怎麽用?TypeScript left使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了left函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: lookupIndices
const lookupResult: T.Task<P.Either<string, LookupResult>> = T.co(function* () {
const nonIndexResult: LookupResult = yield settings.lookupFile(pieces);
if (nonIndexResult.tag === LookupResultType.LRFILE) {
return T.pure(P.right(nonIndexResult));
}
const eIndexResult: P.Either<string, LookupResult> = yield lookupIndices(
settings.indices.map(ix => dropLastIfNull(pieces.concat(ix)))
);
if (P.isLeft(eIndexResult)) {
return T.pure(P.left(eIndexResult.value));
}
const { value: indexResult } = eIndexResult;
if (indexResult.tag === LookupResultType.LRNOTFOUND) {
return T.pure(P.right(nonIndexResult));
}
if (indexResult.tag === LookupResultType.LRFILE && settings.redirectToIndex) {
const file = indexResult.file;
return T.pure(P.left((function () {
const repieces = pieces.slice().reverse();
if (repieces.length === 0) {
return file.name;
}
const lastSegment = repieces[0];
if (lastSegment == '') return file.name;
return `${lastSegment}/${file.name}`;
})()));
}
return T.pure(P.right(indexResult));
});
示例2:
const weekDay: PS.Parser<Weekday> = PS.defParser(({ str, pos }) => {
if ((str.length - pos) < 3)
return P.left({ pos, error: new PS.ParseError('Expected one of day name') });
for (let i = 0; i < 7; i++) {
if (matchToken({ str, pos }, NUM_TO_WEEKDAY[i]) !== null) {
return P.right({ result: i as Weekday, suffix: { str, pos: pos + 3 } });
}
}
return P.left({ pos, error: new PS.ParseError('Expected one of day name') });
});
示例3: kill
kill(e: Error, cb: NodeCallback<void>) {
if (this._status === StateFiber.COMPLETED) {
cb(null, void 0);
return doNothing;
}
let canceler = this.onComplete({
rethrow: false,
handler: () => {
cb(null, void 0);
}
});
switch (this._status) {
case StateFiber.SUSPENDED:
this._interrupt = left(e);
this._status = StateFiber.COMPLETED;
this._step = this._interrupt;
runFiber(this, this._runTick);
break;
case StateFiber.PENDING:
if (this._interrupt === null) {
this._interrupt = left(e);
}
if (this._bracketCount === 0) {
let step = this._step as Canceler | Computation<any>;
this._attempts = createInterpret(
'CONS', createInterpret('FINALIZER',
isComputation(step) ? step.cancel(e)
: typeof step === 'function' ? step(e) : nonCanceler(e)
),
this._attempts as InterpretTask, this._interrupt as any
);
this._status = StateFiber.RETURN;
this._step = null;
this._fail = null;
runFiber(this, ++this._runTick);
}
break;
default:
if (this._interrupt === null) {
this._interrupt = left(e);
}
if (this._bracketCount === 0) {
this._status = StateFiber.RETURN;
this._step = null;
this._fail = null;
}
}
return canceler;
}
示例4: defaultListing
export function defaultListing(pieces: Piece[], folder: Folder): string {
const isTop = pieces.length === 0 || (pieces.length === 1 && pieces[0] === '');
const fps = isTop ? folder : ([left('')] as Folder).concat(folder);
const title = pieces.join('/');
let html = [
'<!doctype html>',
'<html>',
' <head>',
' <meta charset="utf-8">',
' <meta name="viewport" content="width=device-width">',
` <title>Index of ${title === '' ? 'root folder' : title}</title>`,
' <style type="text/css">',
' table { margin: 0 auto; width: 760px; border-collapse: collapse; font-family: \'sans-serif\'; }',
' table, th, td { border: 1px solid #353948; }',
' td.size { text-align: right; font-size: 0.7em; width: 50px }',
' td.date { text-align: right; font-size: 0.7em; width: 130px }',
' td { padding-right: 1em; padding-left: 1em; }',
' th.first { background-color: white; width: 24px }',
' td.first { padding-right: 0; padding-left: 0; text-align: center }',
' tr { background-color: white; }',
' tr.alt { background-color: #A3B5BA}',
' th { background-color: #3C4569; color: white; font-size: 1.125em; }',
' h1 { width: 760px; margin: 1em auto; font-size: 1em; font-family: sans-serif }',
' img { width: 20px }',
' a { text-decoration: none }',
' </style>',
' </head>',
'<body>',
` <h1>Index of ${title === '' ? 'root folder' : title}</h1>`,
renderDirectoryContentsTable(pieces, fps)
].join('\n');
return `${html}\n</body></html>`;
}
示例5: right
function runSync<A>(f: (...args: any[]) => A, args: any[], ctx: any): Either<Error, A> {
try {
let v = f.apply(ctx, args);
return right(v);
} catch (e) {
return left(e);
}
}
示例6: co
return co(function* () {
yield takeAVar(needsRunning);
const a: A = yield maybe(set.task, identity, applyMaybe(modify, ma)) as Task<A>;
yield writeRef(currRef, right(a));
yield putAVar(responseVar, a);
yield delay(set.delay);
const responseVar_: AVar<A> = yield newEmptyAVar;
yield writeRef(currRef, left(responseVar_));
return loop(responseVar_, just(a));
});
示例7: decrypt
export function decrypt(encrypted: string, opts: Options): Either<string, string> {
const components = encrypted.split('.');
if (components.length !== 3) return left('Invalid payload');
setupKeys(opts);
const iv: Buffer = B.toBuffer(components[0]);
const ciphertext = B.toBuffer(components[1]);
const hmac = B.toBuffer(components[2]);
function cleanup() {
if (iv) zeroBuffer(iv);
if (ciphertext) zeroBuffer(ciphertext);
if (hmac) zeroBuffer(hmac);
if (expectedHmac) zeroBuffer(expectedHmac);
}
// make sure IV is right length
if (iv.length !== 16) {
cleanup();
return left('invalid iv length');
}
const expectedHmac = computeHmac(iv, ciphertext, opts);
if (!timingSafeEqual(hmac, expectedHmac)) {
cleanup();
return left('invalid signature');
}
const decipher = createDecipheriv(
opts.encryptionAlgorithm as string,
opts.encryptionKey,
iv
);
let plaintext = decipher.update(ciphertext, 'binary', 'utf8');
plaintext += decipher.final('utf8');
cleanup();
return right(plaintext);
}
示例8: go
function go(e: P.Either<E, P.Either<A, B>>): P.Either<P.Either<E, P.Either<A, B>>, P.Either<E, B>> {
if (P.isLeft(e)) {
return P.right(e);
}
const ret = e.value;
if (P.isLeft(ret)) {
return P.left(f(ret.value));
}
return P.right(ret);
}