a26a13cdaa2ac4d97a7e95b8ec154998f3dc41f8882e1baa204c08d4f43c57282a1165a7f6026be9661bc466da4cf2298750f87bf679c9bcdbaf9a940cf2f6 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * This function takes one parameter and just returns it. Simply put,
  3. * this is like `<T>(x: T): T => x`.
  4. *
  5. * ## Examples
  6. *
  7. * This is useful in some cases when using things like `mergeMap`
  8. *
  9. * ```ts
  10. * import { interval, take, map, range, mergeMap, identity } from 'rxjs';
  11. *
  12. * const source$ = interval(1000).pipe(take(5));
  13. *
  14. * const result$ = source$.pipe(
  15. * map(i => range(i)),
  16. * mergeMap(identity) // same as mergeMap(x => x)
  17. * );
  18. *
  19. * result$.subscribe({
  20. * next: console.log
  21. * });
  22. * ```
  23. *
  24. * Or when you want to selectively apply an operator
  25. *
  26. * ```ts
  27. * import { interval, take, identity } from 'rxjs';
  28. *
  29. * const shouldLimit = () => Math.random() < 0.5;
  30. *
  31. * const source$ = interval(1000);
  32. *
  33. * const result$ = source$.pipe(shouldLimit() ? take(5) : identity);
  34. *
  35. * result$.subscribe({
  36. * next: console.log
  37. * });
  38. * ```
  39. *
  40. * @param x Any value that is returned by this function
  41. * @returns The value passed as the first parameter to this function
  42. */
  43. export declare function identity<T>(x: T): T;
  44. //# sourceMappingURL=identity.d.ts.map