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


TypeScript operators.reduce函數代碼示例

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


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

示例1: higherOrderReduce

export function reduce<T, R>(this: Observable<T>, accumulator: (acc: R, value: T, index?: number) => R, seed?: R): Observable<R> {
  // providing a seed of `undefined` *should* be valid and trigger
  // hasSeed! so don't use `seed !== undefined` checks!
  // For this reason, we have to check it here at the original call site
  // otherwise inside Operator/Subscriber we won't know if `undefined`
  // means they didn't provide anything or if they literally provided `undefined`
  if (arguments.length >= 2) {
    return higherOrderReduce(accumulator, seed)(this);
  }

  return higherOrderReduce(accumulator)(this);
}
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:12,代碼來源:reduce.ts

示例2: filterAny

 function filterAny(values, getter) {
   return of(...values).pipe(
     map(x => getter(x)),
     reduce((a, b) => a.union(b), new TypedFastBitSet()),
     map(mask => results => results.intersection(mask))
   );
 }
開發者ID:kevmo314,項目名稱:canigraduate.uchicago.edu,代碼行數:7,代碼來源:indexes-worker.ts

示例3: type

 type('should accept R typed reducers', () => {
   let a: Observable<{ a: number; b: string }>;
   a.pipe(reduce<{ a?: number; b?: string }>((acc, value) => {
     value.a = acc.a;
     value.b = acc.b;
     return acc;
   }, {}));
 });
開發者ID:MykhailoIskiv,項目名稱:rxjs,代碼行數:8,代碼來源:scan-spec.ts

示例4: getTrainingSet

async function getTrainingSet() {
    const peopleArray = await of(...range(5, 10), 2)
        .pipe(map(x => `https://swapi.co/api/people/?format=json&page=${x}`))
        .pipe(flatMap(x => Axios.get(x).catch(console.error)))
        .pipe(map((x: AxiosResponse) => x.data))
        .pipe(reduce((acc: any[], x: any) => [x, ...acc], []))
        .toPromise();

    console.log(JSON.stringify(peopleArray, null, 2));
}
開發者ID:vba,項目名稱:DecisionTrees,代碼行數:10,代碼來源:starwars.ts

示例5: type

  type('should accept T typed reducers when T is an array', () => {
    let a: Observable<number[]>;
    const reduced = a.pipe(reduce((acc, value) => {
      return acc.concat(value);
    }, []));

    reduced.subscribe(rs => {
      rs[0].toExponential();
    });
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:10,代碼來源:reduce-spec.ts

示例6: it

  it('should reduce with index with seed', (done: MochaDone) => {
    const idx = [0, 1, 2, 3, 4, 5];

    range(0, 6).pipe(reduce((acc, value, index) => {
      expect(idx.shift()).to.equal(index);
      return value;
    }, -1)).subscribe(null, null, () => {
      expect(idx).to.be.empty;
      done();
    });
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:11,代碼來源:reduce-spec.ts

示例7: merge

    proc.on('close', (code: number) => {
      noClose = true;
      let pipesClosed = merge(stdoutCompleted!, stderrCompleted!)
        .pipe(reduce((acc) => acc, true));

      if (code === 0) {
        pipesClosed.subscribe(() => subj.complete());
      } else {
        pipesClosed.subscribe(() => subj.error(new Error(`Failed with exit code: ${code}`)));
      }
    });
開發者ID:paulcbetts,項目名稱:spawn-rx,代碼行數:11,代碼來源:index.ts


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