当前位置: 首页>>代码示例>>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;未经允许,请勿转载。