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


TypeScript prelude.left函数代码示例

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


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

示例1: lookupIndices

 const lookupResult: T.Task<P.Either<string, LookupResult>> = T.co(function* () {
   const nonIndexResult: LookupResult  = yield settings.lookupFile(pieces);
   if (nonIndexResult.tag === LookupResultType.LRFILE) {
     return T.pure(P.right(nonIndexResult));
   }
   const eIndexResult: P.Either<string, LookupResult> = yield lookupIndices(
     settings.indices.map(ix => dropLastIfNull(pieces.concat(ix)))
   );
   if (P.isLeft(eIndexResult)) {
     return T.pure(P.left(eIndexResult.value));
   }
   const { value: indexResult } = eIndexResult;
   if (indexResult.tag === LookupResultType.LRNOTFOUND) {
     return T.pure(P.right(nonIndexResult));
   }
   if (indexResult.tag === LookupResultType.LRFILE && settings.redirectToIndex) {
     const file = indexResult.file;
     return T.pure(P.left((function () {
       const repieces = pieces.slice().reverse();
       if (repieces.length === 0) {
         return file.name;
       }
       const lastSegment = repieces[0];
       if (lastSegment == '') return file.name;
       return `${lastSegment}/${file.name}`;
     })()));
   }
   return T.pure(P.right(indexResult));
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:29,代码来源:static.ts

示例2:

const weekDay: PS.Parser<Weekday> = PS.defParser(({ str, pos }) => {
  if ((str.length - pos) < 3)
    return P.left({ pos, error: new PS.ParseError('Expected one of day name') });

  for (let i = 0; i < 7; i++) {
    if (matchToken({ str, pos }, NUM_TO_WEEKDAY[i]) !== null) {
      return P.right({ result: i as Weekday, suffix: { str, pos: pos + 3 } });
    }
  }

  return P.left({ pos, error: new PS.ParseError('Expected one of day name') });
});
开发者ID:syaiful6,项目名称:jonggrang,代码行数:12,代码来源:date.ts

示例3: kill

  kill(e: Error, cb: NodeCallback<void>) {
    if (this._status === StateFiber.COMPLETED) {
      cb(null, void 0);
      return doNothing;
    }
    let canceler = this.onComplete({
      rethrow: false,
      handler: () => {
        cb(null, void 0);
      }
    });
    switch (this._status) {
      case StateFiber.SUSPENDED:
        this._interrupt = left(e);
        this._status = StateFiber.COMPLETED;
        this._step = this._interrupt;
        runFiber(this, this._runTick);
        break;

      case StateFiber.PENDING:
        if (this._interrupt === null) {
          this._interrupt = left(e);
        }
        if (this._bracketCount === 0) {
          let step = this._step as Canceler | Computation<any>;
          this._attempts = createInterpret(
                              'CONS', createInterpret('FINALIZER',
                                isComputation(step) ? step.cancel(e)
                                : typeof step === 'function' ? step(e) : nonCanceler(e)
                                ),
                              this._attempts as InterpretTask, this._interrupt as any
                          );
          this._status   = StateFiber.RETURN;
          this._step     = null;
          this._fail     = null;
          runFiber(this, ++this._runTick);
        }
        break;

      default:
        if (this._interrupt === null) {
          this._interrupt = left(e);
        }
        if (this._bracketCount === 0) {
          this._status   = StateFiber.RETURN;
          this._step     = null;
          this._fail     = null;
        }
    }

    return canceler;
  }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:52,代码来源:interpreter.ts

示例4: defaultListing

export function defaultListing(pieces: Piece[], folder: Folder): string {
  const isTop = pieces.length === 0 || (pieces.length === 1 && pieces[0] === '');
  const fps = isTop ? folder : ([left('')] as Folder).concat(folder);
  const title = pieces.join('/');
  let html = [
    '<!doctype html>',
    '<html>',
    '  <head>',
    '    <meta charset="utf-8">',
    '    <meta name="viewport" content="width=device-width">',
    `    <title>Index of ${title === '' ? 'root folder' : title}</title>`,
    '    <style type="text/css">',
    '      table { margin: 0 auto; width: 760px; border-collapse: collapse; font-family: \'sans-serif\'; }',
    '      table, th, td { border: 1px solid #353948; }',
    '      td.size { text-align: right; font-size: 0.7em; width: 50px }',
    '      td.date { text-align: right; font-size: 0.7em; width: 130px }',
    '      td { padding-right: 1em; padding-left: 1em; }',
    '      th.first { background-color: white; width: 24px }',
    '      td.first { padding-right: 0; padding-left: 0; text-align: center }',
    '      tr { background-color: white; }',
    '      tr.alt { background-color: #A3B5BA}',
    '      th { background-color: #3C4569; color: white; font-size: 1.125em; }',
    '      h1 { width: 760px; margin: 1em auto; font-size: 1em; font-family: sans-serif }',
    '      img { width: 20px }',
    '      a { text-decoration: none }',
    '    </style>',
    '  </head>',
    '<body>',
    `  <h1>Index of ${title === '' ? 'root folder' : title}</h1>`,
    renderDirectoryContentsTable(pieces, fps)
  ].join('\n');

  return `${html}\n</body></html>`;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:34,代码来源:listing.ts

示例5: right

function runSync<A>(f: (...args: any[]) => A, args: any[], ctx: any): Either<Error, A> {
  try {
    let v = f.apply(ctx, args);
    return right(v);
  } catch (e) {
    return left(e);
  }
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:8,代码来源:interpreter.ts

示例6: co

 return co(function* () {
   yield takeAVar(needsRunning);
   const a: A = yield maybe(set.task, identity, applyMaybe(modify, ma)) as Task<A>;
   yield writeRef(currRef, right(a));
   yield putAVar(responseVar, a);
   yield delay(set.delay);
   const responseVar_: AVar<A> = yield newEmptyAVar;
   yield writeRef(currRef, left(responseVar_));
   return loop(responseVar_, just(a));
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:auto-update.ts

示例7: decrypt

export function decrypt(encrypted: string, opts: Options): Either<string, string> {
  const components = encrypted.split('.');
  if (components.length !== 3) return left('Invalid payload');

  setupKeys(opts);

  const iv: Buffer = B.toBuffer(components[0]);
  const ciphertext = B.toBuffer(components[1]);
  const hmac = B.toBuffer(components[2]);

  function cleanup() {
    if (iv) zeroBuffer(iv);

    if (ciphertext) zeroBuffer(ciphertext);

    if (hmac) zeroBuffer(hmac);

    if (expectedHmac) zeroBuffer(expectedHmac);
  }

  // make sure IV is right length
  if (iv.length !== 16) {
    cleanup();
    return left('invalid iv length');
  }

  const expectedHmac = computeHmac(iv, ciphertext, opts);
  if (!timingSafeEqual(hmac, expectedHmac)) {
    cleanup();
    return left('invalid signature');
  }

  const decipher = createDecipheriv(
    opts.encryptionAlgorithm as string,
    opts.encryptionKey,
    iv
  );
  let plaintext = decipher.update(ciphertext, 'binary', 'utf8');
  plaintext += decipher.final('utf8');

  cleanup();
  return right(plaintext);
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:43,代码来源:encrypt.ts

示例8: go

 function go(e: P.Either<E, P.Either<A, B>>): P.Either<P.Either<E, P.Either<A, B>>, P.Either<E, B>> {
   if (P.isLeft(e)) {
     return P.right(e);
   }
   const ret = e.value;
   if (P.isLeft(ret)) {
     return P.left(f(ret.value));
   }
   return P.right(ret);
 }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:parser.ts


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