first.js 655 B

12345678910111213
  1. import { EmptyError } from '../util/EmptyError';
  2. import { filter } from './filter';
  3. import { take } from './take';
  4. import { defaultIfEmpty } from './defaultIfEmpty';
  5. import { throwIfEmpty } from './throwIfEmpty';
  6. import { identity } from '../util/identity';
  7. export function first(predicate, defaultValue) {
  8. var hasDefaultValue = arguments.length >= 2;
  9. return function (source) {
  10. return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); }));
  11. };
  12. }
  13. //# sourceMappingURL=first.js.map