Skip to content

Instantly share code, notes, and snippets.

View trxcllnt's full-sized avatar

Paul Taylor trxcllnt

View GitHub Profile
@trxcllnt
trxcllnt / concatMany.as
Created April 15, 2013 11:21
concatMany transforms an IEnumerable to an IObservable by selecting an Observable for each Enumerable value, waiting until the Observable is complete, then moving on to the next value in the Enumerable.
function concatMany(enumerable:IEnumerable, selector:Function):IObservable {
return Observable.createWithCancelable(function(observer:IObserver):ICancelable {
const iterator:IEnumerator = enumerable.getEnumerator();
const subscriptions:CompositeCancelable = new CompositeCancelable();
var schedule:Function = function():void {
subscriptions.add(Scheduler.scheduleRecursive(Scheduler.defaultScheduler, function(reschedule:Function):void {
schedule = reschedule;
@trxcllnt
trxcllnt / Main.as
Created April 15, 2013 19:58
concatMany transforms an IEnumerable to an IObservable. concatMany selects each Enumerable value into an Observable, waits for the IObservable to complete, then selects the next Enumerable value.
package
{
import asx.fn.K;
import asx.fn._;
import asx.fn.args;
import asx.fn.getProperty;
import asx.fn.noop;
import asx.fn.partial;
import asx.fn.sequence;
import asx.number.mul;
/*
Observable.mappend maps a value through a selector and returns
a unique Array of the input values and the result(s).
Use mappend when you'd rather not create anonymous value types
just to track the IObservable stream inputs. Takes advantage of
JS's ability to apply an Array as function arguments, giving the
benefit of more readable JS methods.
Pros:
@trxcllnt
trxcllnt / Values.as
Created April 20, 2013 22:26
A dynamic Observable dictionary.
/*
* Copyright (c) 2013 the original author or authors
*
* Permission is hereby granted to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
*/
package org.tinytlf.observables
{
import asx.array.flatten;
import asx.fn.args;
@trxcllnt
trxcllnt / rx-sort.coffee
Last active December 17, 2015 02:39
Observable.sort
rx = require 'rx'
_ = require 'underscore'
Observable = rx.Observable
Observable::sort = (sorter) ->
source = @
Observable.createWithDisposable (observer) ->
list = [];
source.map((val) ->
function initConcatFriction(Rx) {
Rx.Observable.prototype.concatFriction = function (u, xS, yS, vS, aS) {
if (typeof xS !== 'function')
xS = function (m) { return m.x; };
if (typeof yS !== 'function')
yS = function (m) { return m.y; };
if (typeof vS !== 'function')
vS = function (m) { return m.velocity; };
if (typeof aS !== 'function')
@trxcllnt
trxcllnt / client.js
Created November 23, 2013 05:11
Browserify + Rx
// Have to do this to browserify Rx :/
window.global = window;
var Rx = require('rx');
Rx.Observable.interval(100).subscribe(function(i) {
console.log(i);
});
@trxcllnt
trxcllnt / Observable.js
Last active August 29, 2015 14:00
Observable with Lift and Mutate
var Subscriber = require('./Subscriber'),
noop = require('./support/noop')
;
module.exports = (function Observable() {
function fixDisposable(subscriber, disposable) {
var disposableType;
if(disposable != null) {
if((disposableType = typeof disposable) === 'function') {
@trxcllnt
trxcllnt / zone.js
Last active August 29, 2015 14:01
// Zone.create = Observable.create
// Zone#setCallback = Observable#forEach/Observable#subscribe
// Zone#then = Observable#map
// Zone#catch = Observable#catch
//
// A little stub of some zone examples that map 1-1 with Rx. Instead of a zone global,
// the "zone" object is passed in to the function we created the Zone with.
//
// This allows us to run multiple Zones in parallel, for example, if we want to await
// two run two asynchronous operations (say, a file-read and a network request) at the
@trxcllnt
trxcllnt / optional-params-and-tail-call-optimizer.sjs.js
Last active August 29, 2015 14:04
Sweet.js macros for optional/default params, and a macro to unroll tail-recursive functions into imperative loops.
macro parameters {
rule { ($arguments ...) } => { (params ($arguments ...)) }
}
macro params {
// group matchers
rule { ($x:ident = $y:expr , $rest:params (,) ...) } => { $x , $rest (,) ... }
rule { ($x:ident , $rest:params (,) ...) } => { $x , $rest (,) ... }
rule { ($x:ident = $y:expr) } => { $x }