本文整理汇总了TypeScript中@jonggrang/prelude.right函数的典型用法代码示例。如果您正苦于以下问题:TypeScript right函数的具体用法?TypeScript right怎么用?TypeScript right使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了right函数的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: 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);
}
示例3: it
it('can render Cookie secure', () => {
const cookieSecure = CO.createCookie('foo', 'baz', undefined, undefined, true, false, undefined);
assert.deepEqual(
CO.renderCookie(P.nothing, cookieSecure),
P.right('foo=baz; Secure')
);
const cookieNonSecure = CO.createCookie('foo', 'baz', undefined, undefined, false, false, undefined);
assert.deepEqual(
CO.renderCookie(P.nothing, cookieNonSecure),
P.right('foo=baz')
);
});
示例4: 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);
}
}
示例5: stepContinuePure
function stepContinuePure(fib: TaskFiber<any>) {
if (fib._bhead === null) {
fib._status = StateFiber.RETURN;
fib._step = right((fib._step as Pure<any>)._1);
} else {
fib._status = StateFiber.STEP_BIND;
fib._step = (fib._step as Pure<any>)._1;
}
}
示例6: it
it('compete should return the fastest task', function () {
return shouldBe(
right('right'),
S.compete(
T.delay(30).map(() => 'left'),
T.delay(20).map(() => 'right')
)
);
});
示例7: 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));
});
示例8:
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') });
});