Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/e0b3c96bb4f310cebadf to your computer and use it in GitHub Desktop.
Save mattpodwysocki/e0b3c96bb4f310cebadf to your computer and use it in GitHub Desktop.
function toSet(source, type) {
return new AnonymousObservable(function (observer) {
var s = new type();
return source.subscribe(
s.add.bind(s),
observer.onError.bind(observer),
function () {
observer.onNext(s);
observer.onCompleted();
})
});
}
if (!!window.Set) {
Rx.Observable.prototype.toSet = function () {
return toSet(this, window.Set);
};
}
if (!!window.WeakSet) {
Rx.Observable.prototype.toWeakSet = function () {
return toSet(this, window.WeakSet);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment