a zip code crypto-currency system good for red ONLY

first.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { first as higherOrder } from '../operators/first';
  2. /**
  3. * Emits only the first value (or the first value that meets some condition)
  4. * emitted by the source Observable.
  5. *
  6. * <span class="informal">Emits only the first value. Or emits only the first
  7. * value that passes some test.</span>
  8. *
  9. * <img src="./img/first.png" width="100%">
  10. *
  11. * If called with no arguments, `first` emits the first value of the source
  12. * Observable, then completes. If called with a `predicate` function, `first`
  13. * emits the first value of the source that matches the specified condition. It
  14. * may also take a `resultSelector` function to produce the output value from
  15. * the input value, and a `defaultValue` to emit in case the source completes
  16. * before it is able to emit a valid value. Throws an error if `defaultValue`
  17. * was not provided and a matching element is not found.
  18. *
  19. * @example <caption>Emit only the first click that happens on the DOM</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var result = clicks.first();
  22. * result.subscribe(x => console.log(x));
  23. *
  24. * @example <caption>Emits the first click that happens on a DIV</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var result = clicks.first(ev => ev.target.tagName === 'DIV');
  27. * result.subscribe(x => console.log(x));
  28. *
  29. * @see {@link filter}
  30. * @see {@link find}
  31. * @see {@link take}
  32. *
  33. * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
  34. * callback if the Observable completes before any `next` notification was sent.
  35. *
  36. * @param {function(value: T, index: number, source: Observable<T>): boolean} [predicate]
  37. * An optional function called with each item to test for condition matching.
  38. * @param {function(value: T, index: number): R} [resultSelector] A function to
  39. * produce the value on the output Observable based on the values
  40. * and the indices of the source Observable. The arguments passed to this
  41. * function are:
  42. * - `value`: the value that was emitted on the source.
  43. * - `index`: the "index" of the value from the source.
  44. * @param {R} [defaultValue] The default value emitted in case no valid value
  45. * was found on the source.
  46. * @return {Observable<T|R>} An Observable of the first item that matches the
  47. * condition.
  48. * @method first
  49. * @owner Observable
  50. */
  51. export function first(predicate, resultSelector, defaultValue) {
  52. return higherOrder(predicate, resultSelector, defaultValue)(this);
  53. }
  54. //# sourceMappingURL=first.js.map