當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。