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


TypeScript operators.groupBy函数代码示例

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


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

示例1: it

it('should enforce types of duration selector', () => {
  const o = of(1, 2, 3).pipe(groupBy(value => value.toString(), undefined, value => 'foo')); // $ExpectError
  const p = of(1, 2, 3).pipe(groupBy(value => value.toString(), undefined, (value: GroupedObservable<number, number>) => value)); // $ExpectError
  const q = of(1, 2, 3).pipe(groupBy(value => value.toString(), undefined, (value: GroupedObservable<string, string>) => value)); // $ExpectError
  const r = of(1, 2, 3).pipe(groupBy(value => value.toString(), value => Boolean(value), (value: GroupedObservable<string, string>) => value)); // $ExpectError
  const s = of(1, 2, 3).pipe(groupBy(value => value.toString(), value => Boolean(value), (value: GroupedObservable<boolean, boolean>) => value)); // $ExpectError
});
开发者ID:jaychsu,项目名称:RxJS,代码行数:7,代码来源:groupBy-spec.ts

示例2: groupBy

 observable1 = groupByZone1.run(() => {
   return observable1.pipe(
       groupBy((person: any) => {
         expect(Zone.current.name).toEqual(groupByZone1.name);
         return person.age;
       }),
       // return as array of each group
       flatMap((group: any) => {
         return group.pipe(reduce((acc: any, curr: any) => [...acc, curr], []));
       }));
 });
开发者ID:angular,项目名称:zone.js,代码行数:11,代码来源:rxjs.Observable.collection.spec.ts

示例3: from

  public static doGroupRows<T>(data: T[], groupRowsBy) {
    const grouped = [];
    from(data).pipe(
      groupBy((row) => row[groupRowsBy]),
      flatMap((group) => group.pipe(
        reduce((acc: T[], curr: T) => [...acc, curr], []),
      )),
    ).subscribe((row) => grouped.push(row));

    return grouped;
  }
开发者ID:ssuperczynski,项目名称:ng2-easy-table,代码行数:11,代码来源:group-rows.service.ts

示例4: toActions

  /**
   * @internal
   */
  toActions(): Observable<Action> {
    return this.pipe(
      groupBy(getSourceForInstance),
      mergeMap(source$ =>
        source$.pipe(
          exhaustMap(resolveEffectSource),
          map(output => {
            verifyOutput(output, this.errorHandler);

            return output.notification;
          }),
          filter(
            (notification): notification is Notification<Action> =>
              notification.kind === 'N'
          ),
          dematerialize()
        )
      )
    );
  }
开发者ID:AlexChar,项目名称:platform,代码行数:23,代码来源:effect_sources.ts

示例5: groupBy1

 groupBy1() {
   const people = [
     { name: 'Sue', age: 25 },
     { name: 'Joe', age: 30 },
     { name: 'Frank', age: 25 },
     { name: 'Sarah', age: 35 }
   ];
   // emit each person
   const source = from(people);
   // group by age
   const example = source.pipe(
     groupBy(person => person.age),
     //  return each item in group as array
     mergeMap(group => group.pipe(toArray()))
   );
   /*
     output:
     [{age: 25, name: "Sue"},{age: 25, name: "Frank"}]
     [{age: 30, name: "Joe"}]
     [{age: 35, name: "Sarah"}]
   */
   const subscribe = example.subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:23,代码来源:transforming.service.ts

示例6: executeCellEpic

export function executeCellEpic(
  action$: ActionsObservable<ExecuteCell | ExecuteFocusedCell>,
  state$: any
) {
  return action$.pipe(
    ofType(actions.EXECUTE_CELL, actions.EXECUTE_FOCUSED_CELL),
    mergeMap((action: ExecuteCell | ExecuteFocusedCell) => {
      if (action.type === actions.EXECUTE_FOCUSED_CELL) {
        const contentRef = action.payload.contentRef;
        const state = state$.value;
        const model = selectors.model(state, { contentRef });
        // If it's not a notebook, we shouldn't be here
        if (!model || model.type !== "notebook") {
          return empty();
        }

        const id = model.cellFocused;

        if (!id) {
          throw new Error("attempted to execute without an id");
        }
        return of(
          actions.executeCell({ id, contentRef: action.payload.contentRef })
        );
      }
      return of(action);
    }),
    tap((action: ExecuteCell) => {
      if (!action.payload.id) {
        throw new Error("execute cell needs an id");
      }
    }),
    // Split stream by cell IDs
    groupBy((action: ExecuteCell) => action.payload.id),
    // Work on each cell's stream
    map(cellAction$ =>
      cellAction$.pipe(
        // When a new EXECUTE_CELL comes in with the current ID, we create a
        // a new stream and unsubscribe from the old one.
        switchMap((action: ExecuteCell) => {
          const { id } = action.payload;

          const state = state$.value;

          const contentRef = action.payload.contentRef;
          const model = selectors.model(state, { contentRef });

          // If it's not a notebook, we shouldn't be here
          if (!model || model.type !== "notebook") {
            return empty();
          }

          const cell = selectors.notebook.cellById(model, {
            id
          });
          if (!cell) {
            return empty();
          }

          // We only execute code cells
          if ((cell as any).get("cell_type") === "code") {
            const source = cell.get("source", "");

            const message = createExecuteRequest(source);

            return createExecuteCellStream(
              action$,
              state,
              message,
              id,
              action.payload.contentRef
            ).pipe(
              catchError((error, source) =>
                merge(
                  of(
                    actions.executeFailed({
                      error,
                      contentRef: action.payload.contentRef
                    })
                  ),
                  source
                )
              )
            );
          }
          return empty();
        })
      )
    ),
    // Bring back all the inner Observables into one stream
    mergeAll(),
    catchError((error: Error, source) => {
      // Either we ensure that all errors are caught when the action.payload.contentRef
      // is in scope or we make this be a generic ERROR
      // $FlowFixMe: see above
      return merge(
        of(
          actions.executeFailed({
            error
          })
//.........这里部分代码省略.........
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:101,代码来源:execute.ts


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