本文整理汇总了TypeScript中src/monet.Maybe.map方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Maybe.map方法的具体用法?TypeScript Maybe.map怎么用?TypeScript Maybe.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src/monet.Maybe
的用法示例。
在下文中一共展示了Maybe.map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: NonEmptyList
import { NonEmptyList, NEL, List, Nil, Maybe } from 'src/monet';
const nel: NEL<string> = NonEmptyList('a', List('b'));
const nonempty: NonEmptyList<number> = NEL(0, List(12));
const nelBool: NEL<boolean> = nel.flatMap((str: string) => NEL.of(!str, List(Boolean(str))));
const nil = nelBool.filter(a => a).filter(a => !a);
const nel2 = NEL.fromList(nil).cata(() => NEL.unit(true), a => a);
const nel3 = NEL.fromList(Nil).cata(() => NEL.pure(true), a => a);
const taken: NonEmptyList<number> = nel2.takeLeft(nel3).takeRight(nonempty);
const tail: List<number> = taken.tail();
const xx: NEL<number> = taken.tails().map(e => e.head()).mapTails(t => t.extract()).cojoin().bind(t => t).reverse();
const yy: NEL<string> = xx.cobind(t => t.ap(NonEmptyList(String))).coflatMap(t => t.extract()).head();
const foldedL: Maybe<NEL<string>> = NonEmptyList.fromList(tail).map(t =>
t.tails().foldLeft(yy)((acc, n) => acc.concat(n.ap(NEL(String)))));
const foldedR: NonEmptyList<boolean> = foldedL.map(f => f.cojoin()).map(ff => ff.foldRight(nelBool)((v, acc) =>
acc.append(v.map(Boolean)))).orJust(nelBool);
console.log(true === foldedR.reduceLeft((acc, n) => acc && n));