當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript monet.Validation類代碼示例

本文整理匯總了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());
    }
}
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:7,代碼來源:validation-spec.ts

示例2: log

function log(message: Validation<string, string>) {
    return message.cata(err => IO(() => {
        console.error(err);
    }), msg => IO(() => {
        console.log(msg);
    }));
}
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:7,代碼來源:validation-spec.ts

示例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);
}
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:7,代碼來源:validation-spec.ts

示例4:

const wrappedGreeting: Validation<string, string> = wrapped.bind(v => v.payload ?
    Validation.success<string, string>(v.payload) :
    Validation.fail<string, string>('NonePayload'));
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:3,代碼來源:validation-spec.ts

示例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);
}
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:31,代碼來源:validation-spec.ts


注:本文中的src/monet.Validation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。