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


TypeScript monet.IO函數代碼示例

本文整理匯總了TypeScript中src/monet.IO函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript IO函數的具體用法?TypeScript IO怎麽用?TypeScript IO使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IO函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: log2

function log2(message: Maybe<string>): IO<void> {
    return message.fold(IO(() => {
        console.warn('Nothing to log.')
    }))(msg => IO(() => {
        console.log(msg);
    }));
}
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:7,代碼來源:maybe-spec.ts

示例2: IO

 }), msg => IO(() => {
     console.log(msg);
 }));
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:3,代碼來源:maybe-spec.ts

示例3: IO

const oneChar: IO<string> = IO.pure(() => IO(() => '1')).join<string>();
開發者ID:cwmyers,項目名稱:monet.js,代碼行數:1,代碼來源:io-spec.ts

示例4: IO

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

示例5: 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.IO函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。