本文整理匯總了TypeScript中src/monet.Validation.chain方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Validation.chain方法的具體用法?TypeScript Validation.chain怎麽用?TypeScript Validation.chain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類src/monet.Validation
的用法示例。
在下文中一共展示了Validation.chain方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getMessage
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);
}
const messageErrors: string = getHttpError(404).failMap<string>(String).failMap(Array)
.ap(getHttpError(400).failMap(String).failMap(Array).map(v => t => v + t))
.ap(getHttpError(500).failMap(String).failMap(Array).map(v => t => v + t))
.cata(e => e.join(), v => v);