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


TypeScript operators.partition函数代码示例

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


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

示例1: partition2

 partition2() {
   const source = from([1, 2, 3, 4, 5, 6]);
   // if greater than 3 throw
   const example = source.pipe<{success: number, error: number},{success: number, error: number}>(
     map(val => {
       if (val > 3) {
         // throw `${val} greater than 3!`;
       }
       return { success: val, error: null };
     }),
     catchError(val => of({ success: null, error: val }))
   );
   // split on success or error
   const [success, error] = partition<{success: number, error: number}>(res => res.success !== null)(example);
   /*
     Output:
     "Success! 1"
     "Success! 2"
     "Success! 3"
     "Error! 4 greater than 3!"
   */
   const subscribe = merge(
     success.pipe(map(val => `Success! ${val.success}`)),
     error.pipe(map(val => `Error! ${val.error}`))
   ).subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:26,代码来源:transforming.service.ts

示例2: partition1

 partition1() {
   const source = from([1, 2, 3, 4, 5, 6]);
   // first value is true, second false
   const [evens, odds] = partition<number>(val => val % 2 === 0)(source);
   /*
     Output:
     "Even: 2"
     "Even: 4"
     "Even: 6"
     "Odd: 1"
     "Odd: 3"
     "Odd: 5"
   */
   const subscribe = merge(
     evens.pipe(map(val => `Even: ${val}`)),
     odds.pipe(map(val => `Odd: ${val}`))
   ).subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:18,代码来源:transforming.service.ts

示例3: fetchNodesNetwork

export function fetchNodesNetwork(): Observable<
  RequestResponse<NodesNetworkResponse>
> {
  const [success, error] = partition(
    (response: RequestResponse<NodesNetworkResponse>) => response.code < 300
  )(request<NodeNetworkResponse[]>("/net/v1/nodes").pipe(share()));

  return merge(
    success,
    error.pipe(
      tap((response: RequestResponse<NodesNetworkResponse>) => {
        const responseMessage =
          response.response && typeof response.response === "object"
            ? JSON.stringify(response.response)
            : response.response;
        throw new Error(
          `Network Nodes API request failed: ${response.code} ${
            response.message
          }:${responseMessage}`
        );
      })
    )
  );
}
开发者ID:dcos,项目名称:dcos-ui,代码行数:24,代码来源:NodesNetworkClient.ts

示例4: expect

 const part: any = partitionZone.run(() => {
   return observable1.pipe(partition((val: any) => {
     expect(Zone.current.name).toEqual(partitionZone.name);
     return val % 2 === 0;
   }));
 });
开发者ID:angular,项目名称:zone.js,代码行数:6,代码来源:rxjs.Observable.map.spec.ts

示例5: higherOrder

export function partition<T>(this: Observable<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
  return higherOrder(predicate, thisArg)(this);
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:3,代码来源:partition.ts


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