本文整理汇总了TypeScript中src/monet.Validation类的典型用法代码示例。如果您正苦于以下问题:TypeScript Validation类的具体用法?TypeScript Validation怎么用?TypeScript Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validation类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: log3
function log3(message: Validation<string, string>): void {
if (message.isSuccess()) {
console.log(message.success());
} else if (message.isFail()) {
console.warn(message.fail());
}
}
示例2: log
function log(message: Validation<string, string>) {
return message.cata(err => IO(() => {
console.error(err);
}), msg => IO(() => {
console.log(msg);
}));
}
示例3: log2
function log2(message: Validation<string, string>): IO<void> {
return message.bimap(err => IO(() => {
console.error(err);
}), msg => IO(() => {
console.log(msg);
})).cata(e => e, m => m);
}
示例4:
const wrappedGreeting: Validation<string, string> = wrapped.bind(v => v.payload ?
Validation.success<string, string>(v.payload) :
Validation.fail<string, string>('NonePayload'));
示例5: getMessage
payload: string;
}
function getMessage(msg: IMessage) {
if (msg && msg.hasOwnProperty('type')) {
return Success<string, IMessage>(msg);
}
return Fail<string, IMessage>('BadMessageFormat.');
}
const wrapped = getMessage({type: 'MESSAGE', payload: 'Hello World'});
console.assert(!(wrapped.isSuccess() === wrapped.isFail()));
const wrappedGreeting: Validation<string, string> = wrapped.bind(v => v.payload ?
Validation.success<string, string>(v.payload) :
Validation.fail<string, string>('NonePayload'));
const wrappedType = wrapped.flatMap(getType);
const unpacked = wrappedGreeting.chain(g => wrappedType.map(t => `Type: ${t} - Body: ${g}`));
log(unpacked).run();
log2(getMessage(null).flatMap(getType)).performUnsafeIO();
log3(getMessage({type: 'x', payload: null}).chain(getType));
const nameError: string = Fail('-- Adamovisch').failMap(n => n.split(' ').shift()).fail();
function getHttpError(code: number) {
return Fail<number, string>(code);
}