本文整理汇总了TypeScript中src/monet.NEL类的典型用法代码示例。如果您正苦于以下问题:TypeScript NEL类的具体用法?TypeScript NEL怎么用?TypeScript NEL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NEL类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const nel3 = NEL.fromList(Nil).cata(() => NEL.pure(true), a => a);
示例2: List
const nelBool: NEL<boolean> = nel.flatMap((str: string) => NEL.of(!str, List(Boolean(str))));
示例3: 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));