Skip to content

Instantly share code, notes, and snippets.

View cwharris's full-sized avatar
🖖

Christopher Harris cwharris

🖖
View GitHub Profile
@cwharris
cwharris / rxdd.js
Last active December 17, 2015 04:38
Stick THIS in your browser and run it.
Rx.Observable.select = function (element, source) {
return source.select(function (value) {
return {
element: element,
value: value
};
});
};
Rx.Observable.prototype.obsFilter = function (func) {
var self = this;
return Rx.Observable.createWithDisposable(function (o) {
self.subscribe(function (source) {
var subject = null;
@cwharris
cwharris / Program.cs
Last active December 16, 2015 22:49
Reactive Primitives
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace ReactivePrimitives
{
class Program
{
static void Main(string[] args)
{
@cwharris
cwharris / flatMap.js
Created May 2, 2013 18:20
OH LOOK IT IS GOOD FRIEND FLAT MAP COME TO SAVE US ALL FROM DOOM.
function flatMap (array, func) {
return Array.prototype.concat.apply([], array.map(func));
};
static void Main(string[] args)
{
var items = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
.Select(x =>
{
Console.WriteLine(x);
return x;
})
.Select(x => Observable.Range(x, 1))
.Concat()
@cwharris
cwharris / combineTemplate.js
Last active December 12, 2015 01:09
Rx.Observable.combineTemplate takes an object with key/value pairs of observables, and returns an observable which yields objects with key/value pairs of values which have been provided internally using Rx.Observable.combineLatest.
Rx.Observable.combineTemplate = function(sources) {
var keys = [];
var values = [];
for (var key in sources) {
keys.push(key);
values.push(sources[key]);
}
// combineLatest(obs1, obs2, selector)
// combineLatest([obs1, obs2], selector)
observableProto.combineLatest = function () {
var args = slice.call(arguments);
// (args[0] instanceof Array ? args[0] : args).unshift(this);
if (args[0] instanceof Array) {
args[0].unshift(this);
} else {
args.unshift(this);