elementAt.js 832 B

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