operators/map.js

  1. import { Observable } from '../Observable';
  2. import { passThroughNext } from './passThroughNext';
  3. /**
  4. * Will map each value to a new value using the callback
  5. *
  6. * @memberof operators
  7. *
  8. * @param {Observable} source$
  9. * @param {Function} mapCallback
  10. * @returns {Observable}
  11. */
  12. export const map = function (source$, mapCallback) {
  13. return passThroughNext(source$, function ({ next }, value) {
  14. next(mapCallback(value));
  15. });
  16. };
  17. Observable.map = map;
  18. Observable.prototype.map = function (mapCallback) {
  19. return map(this, mapCallback);
  20. };