当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript monet.Right函数代码示例

本文整理汇总了TypeScript中src/monet.Right函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Right函数的具体用法?TypeScript Right怎么用?TypeScript Right使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Right函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

const wrappedGreeting: Either<string, string> = wrapped.bind(v => v.payload ?
    Right<string, string>(v.payload) :
    Left<string, string>('NonePayload'));
开发者ID:cwmyers,项目名称:monet.js,代码行数:3,代码来源:either-spec.ts

示例2: getMessage

function getMessage(msg: IMessage) {
    if (msg && msg.hasOwnProperty('type')) {
        return Right<string, IMessage>(msg);
    }
    return Left<string, IMessage>('BadMessageFormat.');
}
开发者ID:cwmyers,项目名称:monet.js,代码行数:6,代码来源:either-spec.ts

示例3: getType

function getType(action) {
    return action.type === 'MESSAGE' ? Right<string, string>(action.type) : Left<string, string>('BadType');
}
开发者ID:cwmyers,项目名称:monet.js,代码行数:3,代码来源:either-spec.ts

示例4: List

    .takeLeft(List.of(true, Nil))
    .takeRight(List.unit(['a', 'b', 'c']))
    .map(List.fromArray);
const y: List<List<string>> = x.join<string>()
    .flatMap(s => List.pure(`Value: ${s}`).cons(s))
    .tails();
const z: List<string> = y.flatten<string>()
    .reverse().snoc('Ehh…')
    .concat(List<string>())
    .append(List('WOW!'));
const a: number = z.tails().foldLeft(0)((acc, t) => acc + t.size());
const b: List<Maybe<number>> = x.foldRight(z)((l, acc) => acc.append(l))
    .ap(List(Number, List(e => parseInt(e, 10))))
    .headMaybe().map(h => List(h)).orJust(List(0))
    .tails().map(t => t.filter(n => !isNaN(n)))
    .map(t => t.size() > 0 ? Some(t.head()) : None<number>());
const c: List<number> = b.flattenMaybe<number>().chain(n => y.bind(ls => ls).map(s => Number(s) + n));


const maybeList: Maybe<List<string>> = List(Some('A')).sequenceMaybe<string>();
const eitherList: Either<string, List<string>> = List(Right('A')).sequenceEither<string, string>();
const successOfList: Validation<List<string>, List<string>> = List(Success('A')).sequenceValidation<string, string>();
const ioOfList: IO<List<string>> = List(IO(() =>'A')).sequenceIO<string>();
const readerOfList: Reader<string, List<string>> = List(Reader(x => x + 'A')).sequenceReader<string, string>();

const maybeList2: Maybe<List<string>> = List(Some('A')).sequence<string>(Maybe);
const eitherList2: Either<string, List<string>> = List(Right('A')).sequence<string, string>(Either);
const successOfList2: Validation<List<string>, List<string>> = List(Success('A')).sequence<string, string>(Validation);
const ioOfList2: IO<List<string>> = List(IO(() =>'A')).sequence<string>(IO);
const readerOfList2: Reader<string, List<string>> = List(Reader(x => x + 'A')).sequence<string, string>(Reader);
开发者ID:cwmyers,项目名称:monet.js,代码行数:30,代码来源:list-spec.ts


注:本文中的src/monet.Right函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。