elementAt.js 690 B

123456789101112131415
  1. import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
  2. import { filter } from './filter';
  3. import { throwIfEmpty } from './throwIfEmpty';
  4. import { defaultIfEmpty } from './defaultIfEmpty';
  5. import { take } from './take';
  6. export function elementAt(index, defaultValue) {
  7. if (index < 0) {
  8. throw new ArgumentOutOfRangeError();
  9. }
  10. var hasDefaultValue = arguments.length >= 2;
  11. return function (source) {
  12. return source.pipe(filter(function (v, i) { return i === index; }), take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new ArgumentOutOfRangeError(); }));
  13. };
  14. }
  15. //# sourceMappingURL=elementAt.js.map