import { __values as s, __awaiter as u, __generator as v, __asyncValues as d } from "./index-tslib.es6.js";
import { isArrayLike as y } from "./index-isArrayLike.js";
import { isPromise as h } from "./index-isPromise.js";
import { Observable as c } from "./index-Observable.js";
import { isInteropObservable as w } from "./index-isInteropObservable.js";
import { isAsyncIterable as p } from "./index-isAsyncIterable.js";
import { createInvalidObservableTypeError as I } from "./index-throwUnobservableError.js";
import { isIterable as x } from "./index-isIterable.js";
import { isReadableStreamLike as k, readableStreamLikeToAsyncGenerator as A } from "./index-isReadableStreamLike.js";
import { isFunction as L } from "./index-isFunction.js";
import { reportUnhandledError as O } from "./index-reportUnhandledError.js";
import { observable as S } from "./index-observable2.js";
function M(r) {
  if (r instanceof c)
    return r;
  if (r != null) {
    if (w(r))
      return E(r);
    if (y(r))
      return P(r);
    if (h(r))
      return T(r);
    if (p(r))
      return m(r);
    if (x(r))
      return g(r);
    if (k(r))
      return F(r);
  }
  throw I(r);
}
function E(r) {
  return new c(function(e) {
    var n = r[S]();
    if (L(n.subscribe))
      return n.subscribe(e);
    throw new TypeError("Provided object does not correctly implement Symbol.observable");
  });
}
function P(r) {
  return new c(function(e) {
    for (var n = 0; n < r.length && !e.closed; n++)
      e.next(r[n]);
    e.complete();
  });
}
function T(r) {
  return new c(function(e) {
    r.then(function(n) {
      e.closed || (e.next(n), e.complete());
    }, function(n) {
      return e.error(n);
    }).then(null, O);
  });
}
function g(r) {
  return new c(function(e) {
    var n, t;
    try {
      for (var a = s(r), f = a.next(); !f.done; f = a.next()) {
        var l = f.value;
        if (e.next(l), e.closed)
          return;
      }
    } catch (i) {
      n = { error: i };
    } finally {
      try {
        f && !f.done && (t = a.return) && t.call(a);
      } finally {
        if (n) throw n.error;
      }
    }
    e.complete();
  });
}
function m(r) {
  return new c(function(e) {
    R(r, e).catch(function(n) {
      return e.error(n);
    });
  });
}
function F(r) {
  return m(A(r));
}
function R(r, e) {
  var n, t, a, f;
  return u(this, void 0, void 0, function() {
    var l, i;
    return v(this, function(o) {
      switch (o.label) {
        case 0:
          o.trys.push([0, 5, 6, 11]), n = d(r), o.label = 1;
        case 1:
          return [4, n.next()];
        case 2:
          if (t = o.sent(), !!t.done) return [3, 4];
          if (l = t.value, e.next(l), e.closed)
            return [2];
          o.label = 3;
        case 3:
          return [3, 1];
        case 4:
          return [3, 11];
        case 5:
          return i = o.sent(), a = { error: i }, [3, 11];
        case 6:
          return o.trys.push([6, , 9, 10]), t && !t.done && (f = n.return) ? [4, f.call(n)] : [3, 8];
        case 7:
          o.sent(), o.label = 8;
        case 8:
          return [3, 10];
        case 9:
          if (a) throw a.error;
          return [7];
        case 10:
          return [7];
        case 11:
          return e.complete(), [2];
      }
    });
  });
}
export {
  P as fromArrayLike,
  m as fromAsyncIterable,
  E as fromInteropObservable,
  g as fromIterable,
  T as fromPromise,
  F as fromReadableStreamLike,
  M as innerFrom
};
